clash-prelude-0.99.2: CAES Language for Synchronous Hardware - Prelude library

Copyright(C) 2016 University of Twente
2017 Myrtle Software Ltd QBayLogic Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell2010

Clash.XException

Contents

Description

X: An exception for uninitialized values

>>> show (errorX "undefined" :: Integer, 4 :: Int)
"(*** Exception: X: undefined
CallStack (from HasCallStack):
...
>>> showX (errorX "undefined" :: Integer, 4 :: Int)
"(X,4)"
Synopsis

X: An exception for uninitialized values

data XException #

An exception representing an "uninitialised" value.

errorX :: HasCallStack => String -> a #

Like error, but throwing an XException instead of an ErrorCall

The ShowX methods print these error-values as "X"; instead of error'ing out with an exception.

isX :: NFData a => a -> Either String a #

Fully evaluate a value, returning Left msg if is throws XException.

isX 42               = Right 42
isX (XException msg) = Left msg
isX _|_              = _|_

maybeX :: NFData a => a -> Maybe a #

Fully evaluate a value, returning Nothing if is throws XException.

maybeX 42               = Just 42
maybeX (XException msg) = Nothing
maybeX _|_              = _|_

Printing X exceptions as "X"

class ShowX a where #

Like the Show class, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

>>> show (errorX "undefined" :: Integer, 4 :: Int)
"(*** Exception: X: undefined
CallStack (from HasCallStack):
...
>>> showX (errorX "undefined" :: Integer, 4 :: Int)
"(X,4)"

Can be derived using Generics:

{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}

import Clash.Prelude
import GHC.Generics

data T = MkTA Int | MkTB Bool
  deriving (Show,Generic,ShowX)

Methods

showsPrecX :: Int -> a -> ShowS #

Like showsPrec, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

showX :: a -> String #

Like show, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

showListX :: [a] -> ShowS #

Like showList, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

showsPrecX :: (Generic a, GShowX (Rep a)) => Int -> a -> ShowS #

Like showsPrec, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

Instances
ShowX Bool # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Bool -> ShowS #

showX :: Bool -> String #

showListX :: [Bool] -> ShowS #

ShowX Char # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Char -> ShowS #

showX :: Char -> String #

showListX :: [Char] -> ShowS #

ShowX Double # 
Instance details

Defined in Clash.XException

ShowX Float # 
Instance details

Defined in Clash.XException

ShowX Int # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Int -> ShowS #

showX :: Int -> String #

showListX :: [Int] -> ShowS #

ShowX Int8 # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Int8 -> ShowS #

showX :: Int8 -> String #

showListX :: [Int8] -> ShowS #

ShowX Int16 # 
Instance details

Defined in Clash.XException

ShowX Int32 # 
Instance details

Defined in Clash.XException

ShowX Int64 # 
Instance details

Defined in Clash.XException

ShowX Integer # 
Instance details

Defined in Clash.XException

ShowX Word # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Word -> ShowS #

showX :: Word -> String #

showListX :: [Word] -> ShowS #

ShowX Word8 # 
Instance details

Defined in Clash.XException

ShowX Word16 # 
Instance details

Defined in Clash.XException

ShowX Word32 # 
Instance details

Defined in Clash.XException

ShowX Word64 # 
Instance details

Defined in Clash.XException

ShowX () # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> () -> ShowS #

showX :: () -> String #

showListX :: [()] -> ShowS #

ShowX String # 
Instance details

Defined in Clash.XException

ShowX Bit # 
Instance details

Defined in Clash.Sized.Internal.BitVector

Methods

showsPrecX :: Int -> Bit -> ShowS #

showX :: Bit -> String #

showListX :: [Bit] -> ShowS #

ShowX a => ShowX [a] # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> [a] -> ShowS #

showX :: [a] -> String #

showListX :: [[a]] -> ShowS #

ShowX a => ShowX (Maybe a) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Maybe a -> ShowS #

showX :: Maybe a -> String #

showListX :: [Maybe a] -> ShowS #

ShowX a => ShowX (Ratio a) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Ratio a -> ShowS #

showX :: Ratio a -> String #

showListX :: [Ratio a] -> ShowS #

ShowX a => ShowX (Complex a) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Complex a -> ShowS #

showX :: Complex a -> String #

showListX :: [Complex a] -> ShowS #

KnownNat n => ShowX (BitVector n) # 
Instance details

Defined in Clash.Sized.Internal.BitVector

ShowX (Index n) # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

showsPrecX :: Int -> Index n -> ShowS #

showX :: Index n -> String #

showListX :: [Index n] -> ShowS #

KnownNat n => ShowX (BNat n) # 
Instance details

Defined in Clash.Promoted.Nat

Methods

showsPrecX :: Int -> BNat n -> ShowS #

showX :: BNat n -> String #

showListX :: [BNat n] -> ShowS #

KnownNat n => ShowX (UNat n) # 
Instance details

Defined in Clash.Promoted.Nat

Methods

showsPrecX :: Int -> UNat n -> ShowS #

showX :: UNat n -> String #

showListX :: [UNat n] -> ShowS #

ShowX (SNat n) # 
Instance details

Defined in Clash.Promoted.Nat

Methods

showsPrecX :: Int -> SNat n -> ShowS #

showX :: SNat n -> String #

showListX :: [SNat n] -> ShowS #

ShowX (Unsigned n) # 
Instance details

Defined in Clash.Sized.Internal.Unsigned

ShowX (Signed n) # 
Instance details

Defined in Clash.Sized.Internal.Signed

Methods

showsPrecX :: Int -> Signed n -> ShowS #

showX :: Signed n -> String #

showListX :: [Signed n] -> ShowS #

(ShowX a, ShowX b) => ShowX (Either a b) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> Either a b -> ShowS #

showX :: Either a b -> String #

showListX :: [Either a b] -> ShowS #

(ShowX a, ShowX b) => ShowX (a, b) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b) -> ShowS #

showX :: (a, b) -> String #

showListX :: [(a, b)] -> ShowS #

ShowX a => ShowX (Vec n a) # 
Instance details

Defined in Clash.Sized.Vector

Methods

showsPrecX :: Int -> Vec n a -> ShowS #

showX :: Vec n a -> String #

showListX :: [Vec n a] -> ShowS #

ShowX a => ShowX (RTree n a) # 
Instance details

Defined in Clash.Sized.RTree

Methods

showsPrecX :: Int -> RTree n a -> ShowS #

showX :: RTree n a -> String #

showListX :: [RTree n a] -> ShowS #

(ShowX a, ShowX b, ShowX c) => ShowX (a, b, c) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c) -> ShowS #

showX :: (a, b, c) -> String #

showListX :: [(a, b, c)] -> ShowS #

(size ~ (int + frac), KnownNat frac, Integral (rep size)) => ShowX (Fixed rep int frac) # 
Instance details

Defined in Clash.Sized.Fixed

Methods

showsPrecX :: Int -> Fixed rep int frac -> ShowS #

showX :: Fixed rep int frac -> String #

showListX :: [Fixed rep int frac] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d) => ShowX (a, b, c, d) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d) -> ShowS #

showX :: (a, b, c, d) -> String #

showListX :: [(a, b, c, d)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e) => ShowX (a, b, c, d, e) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e) -> ShowS #

showX :: (a, b, c, d, e) -> String #

showListX :: [(a, b, c, d, e)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f) => ShowX (a, b, c, d, e, f) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f) -> ShowS #

showX :: (a, b, c, d, e, f) -> String #

showListX :: [(a, b, c, d, e, f)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g) => ShowX (a, b, c, d, e, f, g) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g) -> ShowS #

showX :: (a, b, c, d, e, f, g) -> String #

showListX :: [(a, b, c, d, e, f, g)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h) => ShowX (a, b, c, d, e, f, g, h) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h) -> ShowS #

showX :: (a, b, c, d, e, f, g, h) -> String #

showListX :: [(a, b, c, d, e, f, g, h)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i) => ShowX (a, b, c, d, e, f, g, h, i) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j) => ShowX (a, b, c, d, e, f, g, h, i, j) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j, ShowX k) => ShowX (a, b, c, d, e, f, g, h, i, j, k) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j, k) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j, k) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j, k)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j, ShowX k, ShowX l) => ShowX (a, b, c, d, e, f, g, h, i, j, k, l) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j, k, l) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j, k, l) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j, k, l)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j, ShowX k, ShowX l, ShowX m) => ShowX (a, b, c, d, e, f, g, h, i, j, k, l, m) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j, k, l, m)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j, ShowX k, ShowX l, ShowX m, ShowX n) => ShowX (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] -> ShowS #

(ShowX a, ShowX b, ShowX c, ShowX d, ShowX e, ShowX f, ShowX g, ShowX h, ShowX i, ShowX j, ShowX k, ShowX l, ShowX m, ShowX n, ShowX o) => ShowX (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # 
Instance details

Defined in Clash.XException

Methods

showsPrecX :: Int -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> ShowS #

showX :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> String #

showListX :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] -> ShowS #

showsX :: ShowX a => a -> ShowS #

Like shows, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception.

printX :: ShowX a => a -> IO () #

Like print, but values that normally throw an X exception are converted to "X", instead of error'ing out with an exception

showsPrecXWith :: (Int -> a -> ShowS) -> Int -> a -> ShowS #

Use when you want to create a ShowX instance where:

  • There is no Generic instance for your data type
  • The Generic derived ShowX method would traverse into the (hidden) implementation details of your data type, and you just want to show the entire value as "X".

Can be used like:

data T = ...

instance Show T where ...

instance ShowX T where
  showsPrecX = showsPrecXWith showsPrec

Strict evaluation

seqX :: a -> b -> b infixr 0 #

Like seq, however, whereas seq will always do:

seq  _|_              b = _|_

seqX will do:

seqX (XException msg) b = b
seqX _|_              b = _|_

Orphan instances

Generic (a, b, c, d, e, f, g, h) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h) -> Rep (a, b, c, d, e, f, g, h) x #

to :: Rep (a, b, c, d, e, f, g, h) x -> (a, b, c, d, e, f, g, h) #

Generic (a, b, c, d, e, f, g, h, i) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i) -> Rep (a, b, c, d, e, f, g, h, i) x #

to :: Rep (a, b, c, d, e, f, g, h, i) x -> (a, b, c, d, e, f, g, h, i) #

Generic (a, b, c, d, e, f, g, h, i, j) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j) -> Rep (a, b, c, d, e, f, g, h, i, j) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j) x -> (a, b, c, d, e, f, g, h, i, j) #

Generic (a, b, c, d, e, f, g, h, i, j, k) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j, k) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j, k) -> Rep (a, b, c, d, e, f, g, h, i, j, k) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j, k) x -> (a, b, c, d, e, f, g, h, i, j, k) #

Generic (a, b, c, d, e, f, g, h, i, j, k, l) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j, k, l) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l) x -> (a, b, c, d, e, f, g, h, i, j, k, l) #

Generic (a, b, c, d, e, f, g, h, i, j, k, l, m) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j, k, l, m) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m) x -> (a, b, c, d, e, f, g, h, i, j, k, l, m) #

Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n) x -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) #

Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # 
Instance details

Associated Types

type Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) :: * -> * #

Methods

from :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) x #

to :: Rep (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) x -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) #