Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | generics@haskell.org |
This module defines the basic representation types and the conversion
functions to
and from
. A typical instance for a user-defined datatype
would be:
-- Example datatype data Exp = Const Int | Plus Exp Exp -- Auxiliary datatypes for constructor representations data Const data Plus instance Constructor Const where conName _ = "Const" instance Constructor Plus where conName _ = "Plus" -- Representable instance instance Representable Exp where type Rep Exp = C Const (Var Int) :+: C Plus (Rec Exp :*: Rec Exp) from (Const n) = L (C (Var n)) from (Plus e e') = R (C (Rec e :*: Rec e')) to (L (C (Var n))) = Const n to (R (C (Rec e :*: Rec e'))) = Plus e e'
Documentation
a :*: b |
Var a |
Rec a |
class Constructor c whereSource
Class for datatypes that represent data constructors.
For non-symbolic constructors, only conName
has to be defined.
conName :: t c p q a -> StringSource
conFixity :: t c p q a -> FixitySource
conIsRecord :: t c p q a -> BoolSource
Constructor Tuple_Pair_ | |
Constructor Maybe_Just_ | |
Constructor Maybe_Nothing_ | |
Constructor List_Cons_ | |
Constructor List_Nil_ |
Datatype to represent the fixity of a constructor. An infix declaration
directly corresponds to an application of Infix
.
data Associativity Source
Datatype to represent the associativy of a constructor.
class Representable a whereSource
Representable Bool | |
Representable Char | |
Representable Float | |
Representable Int | |
Representable U | |
Representable [a] | |
Representable (Maybe a) | |
Representable a => Representable (Rec a) | |
Representable a => Representable (Var a) | |
Representable (a, b) | |
(Representable a, Representable b) => Representable (:*: a b) | |
(Representable a, Representable b) => Representable (:+: a b) | |
Representable a => Representable (CEq c p q a) |