clash-lib-1.8.1: Clash: a functional hardware description language - As a library

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

Clash.Core.TermLiteral

Description

Tools to convert a `Term` into its "real" representation

Synopsis

- class TermLiteral a
- showsTypePrec :: TermLiteral a => Int -> Proxy a -> ShowS
- showType :: TermLiteral a => Proxy a -> String
- termToData :: (TermLiteral a, HasCallStack) => Term -> Either Term a
- termToDataError :: forall a. TermLiteral a => Term -> Either String a
- deriveTermLiteral :: Name -> Q [Dec]

# Documentation

class TermLiteral a Source #

Tools to deal with literals encoded as a `Term`.

Minimal complete definition

termToData

#### Instances

Instances details

TermLiteral Term Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Term Source # showsTypePrec :: Int -> Proxy Term -> ShowS Source #
TermLiteral RenderAs Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term RenderAs Source # showsTypePrec :: Int -> Proxy RenderAs -> ShowS Source #
TermLiteral Text Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Text Source # showsTypePrec :: Int -> Proxy Text -> ShowS Source #
TermLiteral String Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term String Source # showsTypePrec :: Int -> Proxy String -> ShowS Source #
TermLiteral Integer Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Integer Source # showsTypePrec :: Int -> Proxy Integer -> ShowS Source #
TermLiteral Natural Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Natural Source # showsTypePrec :: Int -> Proxy Natural -> ShowS Source #
TermLiteral Bool Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Bool Source # showsTypePrec :: Int -> Proxy Bool -> ShowS Source #
TermLiteral Char Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Char Source # showsTypePrec :: Int -> Proxy Char -> ShowS Source #
TermLiteral Int Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Int Source # showsTypePrec :: Int -> Proxy Int -> ShowS Source #
TermLiteral Word Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term Word Source # showsTypePrec :: Int -> Proxy Word -> ShowS Source #
TermLiteral a => TermLiteral (Attr a) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Attr a) Source # showsTypePrec :: Int -> Proxy (Attr a) -> ShowS Source #
TermLiteral (SNat n) Source # | Unsafe warning: If you use this instance in a monomorphic context (e.g., `TermLiteral (SNat 5)`), you need to make very sure that the term corresponds to the literal. If you don't, there will be a mismatch between type level variables and the proof carried in `SNat`s `KnownNat`. Typical usage of this instance will therefore leave the n polymorphic.
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (SNat n) Source # showsTypePrec :: Int -> Proxy (SNat n) -> ShowS Source #
KnownNat n => TermLiteral (Index n) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Index n) Source # showsTypePrec :: Int -> Proxy (Index n) -> ShowS Source #
TermLiteral a => TermLiteral (Assertion' a) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Assertion' a) Source # showsTypePrec :: Int -> Proxy (Assertion' a) -> ShowS Source #
TermLiteral a => TermLiteral (Property' a) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Property' a) Source # showsTypePrec :: Int -> Proxy (Property' a) -> ShowS Source #
TermLiteral a => TermLiteral (Maybe a) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Maybe a) Source # showsTypePrec :: Int -> Proxy (Maybe a) -> ShowS Source #
(TermLiteral a, TermLiteral b) => TermLiteral (Either a b) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Either a b) Source # showsTypePrec :: Int -> Proxy (Either a b) -> ShowS Source #
(TermLiteral a, KnownNat n) => TermLiteral (Vec n a) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (Vec n a) Source # showsTypePrec :: Int -> Proxy (Vec n a) -> ShowS Source #
(TermLiteral a, TermLiteral b) => TermLiteral (a, b) Source # |
Instance details Defined in Clash.Core.TermLiteral Methods termToData :: Term -> Either Term (a, b) Source # showsTypePrec :: Int -> Proxy (a, b) -> ShowS Source #

showsTypePrec Source #

Arguments

:: TermLiteral a |
=> Int | The operator precedence of the enclosing context (a number from `0` to `11`). Function application has precedence `10`. Used to determine whether the result should be wrapped in parentheses.
-> Proxy a | Proxy for a term whose type needs to be pretty printed
-> ShowS |

Pretty print the type of a term (for error messages). Its default implementation uses `Typeable` to print the type. Note that this method is there to allow an instance for `SNat` to exist (and other GADTs imposing `KnownNat`). Without it, GHC would ask for a `KnownNat` constraint on the instance, which would defeat the purpose of it.

showType :: TermLiteral a => Proxy a -> String Source #

Pretty print type `a`

termToData Source #

Arguments

:: (TermLiteral a, HasCallStack) |
=> Term | Term to convert
-> Either Term a | `Left` indicates a failure, containing the (sub)term that failed to translate. `Right` indicates a success.

Convert `Term` to the constant it represents. Will return an error if (one of the subterms) fail to translate.

termToDataError :: forall a. TermLiteral a => Term -> Either String a Source #

Same as `termToData`, but returns printable error message if it couldn't translate a term.

deriveTermLiteral :: Name -> Q [Dec] Source #

Derive a `TermLiteral` instance for given type