clash-prelude-1.8.1: Clash: a functional hardware description language - Prelude library
Copyright(C) 2022 QBayLogic B.V.
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qbaylogic.com>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Clash.XException.MaybeX

Description

Helpers to make XException explicit in the type system. Using these helpers can help programmers account for XExceptions properly in blackbox models or tests. Note that none of these operations can be translated to HDL.

Synopsis

Documentation

data MaybeX a where Source #

Structure helping programmers to deal with XException values. For safety reasons it can't be constructed directly, but should be constructed using either pure or toMaybeX. After construction, it can be deconstructed using either IsX or IsDefined.

Bundled Patterns

pattern IsX :: forall a. String -> MaybeX a

Upon construction, a evaluated to XException

pattern IsDefined :: forall a. a -> MaybeX a

Upon construction, a evaluated to a non-bottom WHNF

Instances

Instances details
Functor MaybeX Source #

Note that fmap is X-strict in its argument. That is, if its input is IsX, its output will be too.

Instance details

Defined in Clash.XException.MaybeX

Methods

fmap :: (a -> b) -> MaybeX a -> MaybeX b #

(<$) :: a -> MaybeX b -> MaybeX a #

Applicative MaybeX Source #

Note that <*> and liftA2 are X-strict in their arguments. That is, if any of their inputs are IsX, their outputs will be too.

Instance details

Defined in Clash.XException.MaybeX

Methods

pure :: a -> MaybeX a #

(<*>) :: MaybeX (a -> b) -> MaybeX a -> MaybeX b #

liftA2 :: (a -> b -> c) -> MaybeX a -> MaybeX b -> MaybeX c #

(*>) :: MaybeX a -> MaybeX b -> MaybeX b #

(<*) :: MaybeX a -> MaybeX b -> MaybeX a #

Show a => Show (MaybeX a) Source # 
Instance details

Defined in Clash.XException.MaybeX

Methods

showsPrec :: Int -> MaybeX a -> ShowS #

show :: MaybeX a -> String #

showList :: [MaybeX a] -> ShowS #

Construction

toMaybeX :: a -> MaybeX a Source #

Construct a MaybeX value. If a evaluates to XException, this function will return IsX. Otherwise, it will return IsDefined.

hasXToMaybeX :: (NFDataX a, NFData a) => a -> MaybeX a Source #

Construct a MaybeX value. If hasX evaluates to Left, this function will return IsX. Otherwise, it will return IsDefined.

Deconstruction

fromMaybeX :: MaybeX a -> a Source #

Deconstruct MaybeX into an a - the opposite of toMaybeX. Be careful when using this function, because it might return an XException if the argument was IsX.

Operations

andX :: MaybeX Bool -> MaybeX Bool -> MaybeX Bool infixr 3 Source #

Implements && accounting for X

X10
XXX0
1X10
0000

orX :: MaybeX Bool -> MaybeX Bool -> MaybeX Bool infixr 2 Source #

Implements || accounting for X

X10
X X  1  X 
1 1  1  1 
0 X  1  0 

maybeX :: (String -> b) -> (a -> b) -> MaybeX a -> b Source #

Map functions over both constructors.