Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | generics@haskell.org |
Summary: Types and related functions for the representation used in EMGM.
EMGM uses a generic sum-of-products view of datatypes encoded into the
Unit
, :+:
(sum), and :*:
(product). Many Haskell datatypes can be
represented in this way. Right-nested sums replace the |
, and right-nested
products replace the arguments to a constructor. Units replace constructors
with no arguments.
Since constructors encode more than just a list of arguments, this library
uses ConDescr
to store that information. This includes name, arity, record
labels, fixity, and operator precedence. Constructor descriptions are useful
for generic operations such as Read
and Show
and possibly others.
Generic functions need to convert values between the Haskell datatype and its structure representation. This is done using the embedding-projection pair, which is simply a pair a functions for translating between two types.
- data Unit = Unit
- data a :+: b
- data a :*: b = a :*: b
- data ConDescr = ConDescr {}
- data ConType
- newtype LblDescr = LblDescr String
- data EP d r = EP {}
- data Fixity
- = Prefix
- | Infix Associativity Prec
- data Associativity
- = LeftAssoc
- | RightAssoc
- | NonAssoc
- type Prec = Int
- prec :: Fixity -> Prec
- minPrec :: Prec
- maxPrec :: Prec
- appPrec :: Prec
- recPrec :: Prec
Structure Representation
The unit, sum, and product types form the sum-of-products view for a Haskell datatype.
Encodes a constructor with no arguments. An analogous standard Haskell type
is ()
.
Unit | The only value of type |
The "sum" encodes 2 constructor alternatives. An analogous standard
Haskell type is
.
Either
a b
The "product" encodes 2 constructor arguments. An analogous standard
Haskell type is (a, b)
.
a :*: b | A pair of arguments |
(Generic g, Rep g a, Rep g b) => Rep g (:*: a b) | |
HasEP [a] (ListS a) | |
Integral a => HasEP (Ratio a) (RatioS a) | |
(Eq a, Eq b) => Eq (:*: a b) | |
(Ord a, Ord b) => Ord (:*: a b) | |
(Read a, Read b) => Read (:*: a b) | |
(Show a, Show b) => Show (:*: a b) | |
HasEP (a, b) (Tuple2S a b) | |
HasEP (a, b, c) (Tuple3S a b c) | |
HasEP (a, b, c, d) (Tuple4S a b c d) | |
HasEP (a, b, c, d, e) (Tuple5S a b c d e) | |
HasEP (a, b, c, d, e, f) (Tuple6S a b c d e f) | |
HasEP (a, b, c, d, e, f, h) (Tuple7S a b c d e f h) |
Constructor Description
A description of the syntax of each constructor provides useful auxiliary information for some generic functions.
Contains useful meta-information about the syntax used in a constructor declaration.
NOTE: It is important that the ConDescr
value accurately describe the
syntax in a constructor declaration. An incorrect description may lead to
faulty Read
or Show
operation.
Encodes the string label for a field in a constructor defined with labeled fields (a.k.a. record syntax).
Embedding-Projection Pair
A pair of a function and its inverse form the isomorphism between a datatype and its structure representation.
The embedding-projection pair contains two functions for converting between
the datatype and its representation. An EP
value preserves an isomorphism
(ignoring _|_
s) between a datatype and its structure representation.
Fixity and Precedence
These are used to determine whether a constructor is infix or not and, if it is infix, what its associativity and precedence are.
A constructor's fixity, associativity, and precedence.
Prefix | Associativity and precedence are the same as function application. |
Infix Associativity Prec |
data Associativity Source
A constructor's associativity.
LeftAssoc | Declared with infixl |
RightAssoc | Declared with infixr |
NonAssoc | Declared with infix |