| 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 :: forall a. (HasCallStack, TermLiteral a) => Term -> Either Term a
- 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
Instances
Arguments
| :: TermLiteral a | |
| => Int | The operator precedence of the enclosing context (a number from |
| -> 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.
termToData :: forall a. (HasCallStack, TermLiteral a) => Term -> Either Term a Source #
Convert Term to the constant it represents. Wraps termToData#: ticks
are stripped from the term (recursively) before delegating, so instances
never have to special-case them.
Arguments
| :: (TermLiteral a, HasCallStack) | |
| => Term | Term to convert |
| -> Either Term a |
|
Convert Term to the constant it represents. Will return an error if
(one of the subterms) fail to translate.
This is the primitive method instances must implement. Callers should
generally use termToData instead, which strips ticks before delegating
to this method.
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