clash-prelude-1.8.4: Clash: a functional hardware description language - Prelude library

Copyright | (C) 2022 QBayLogic B.V.
License | BSD2 (see the file LICENSE)
Maintainer | QBayLogic B.V. <devops@qbaylogic.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Clash.XException.MaybeX

Contents

- Construction
- Deconstruction
- Operations

Description

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

Synopsis

- data MaybeX a where
  - pattern IsX :: String -> MaybeX a
  - pattern IsDefined :: a -> MaybeX a
- toMaybeX :: a -> MaybeX a
- hasXToMaybeX :: (NFDataX a, NFData a) => a -> MaybeX a
- fromMaybeX :: MaybeX a -> a
- andX :: MaybeX Bool -> MaybeX Bool -> MaybeX Bool
- orX :: MaybeX Bool -> MaybeX Bool -> MaybeX Bool
- maybeX :: (String -> b) -> (a -> b) -> MaybeX a -> b

# 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 :: String -> MaybeX a | Upon construction, `a` evaluated to `XException`
pattern IsDefined :: a -> MaybeX a | Upon construction, `a` evaluated to a non-bottom WHNF

#### Instances

Instances details

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 Source # (<*>) :: MaybeX (a -> b) -> MaybeX a -> MaybeX b Source # liftA2 :: (a -> b -> c) -> MaybeX a -> MaybeX b -> MaybeX c Source # (*>) :: MaybeX a -> MaybeX b -> MaybeX b Source # (<*) :: MaybeX a -> MaybeX b -> MaybeX a Source #
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 Source # (<$) :: a -> MaybeX b -> MaybeX a Source #
Show a => Show (MaybeX a) Source # |
Instance details Defined in Clash.XException.MaybeX Methods showsPrec :: Int -> MaybeX a -> ShowS Source # show :: MaybeX a -> String Source # showList :: [MaybeX a] -> ShowS Source #

# 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

| `X` | `1` | `0`
`X` | `X` | `X` | `0`
`1` | `X` | `1` | `0`
`0` | `0` | `0` | `0`

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

Implements `||` accounting for X

| `X` | `1` | `0`
`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.