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'
- data U = U
- data a :+: b
- data a :*: b = a :*: b
- data C c a = C a
- data Var a = Var a
- data Rec a = Rec a
- class Constructor c where
- data Fixity
- = Prefix
- | Infix Associativity Int
- data Associativity
- class Representable a where
Documentation
a :*: b |
C a |
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 a -> StringSource
conFixity :: t c a -> FixitySource
conIsRecord :: t c 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 (C c a) | |
(Representable a, Representable b) => Representable (:*: a b) | |
(Representable a, Representable b) => Representable (:+: a b) |