emgm-0.3.1: Extensible and Modular Generics for the MassesSource codeContentsIndex
Structure Representation
Embedding-Projection Pair
Constructor Description
Fixity and Precedence

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
= L a
| R b
data a :*: b = a :*: b
data EP d r = EP {
from :: d -> r
to :: r -> d
data ConDescr = ConDescr {
conName :: String
conArity :: Int
conLabels :: [String]
conFixity :: Fixity
data ConType
= ConStd
| ConRec [String]
| ConIfx String
data Fixity
= Nonfix
| Infix Prec
| Infixl Prec
| Infixr Prec
prec :: Fixity -> 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.
data Unit Source
The "unit" encodes a constructor with no arguments. An analogous standard Haskell type is ().
UnitThe only value of type Unit (ignoring _|_).
show/hide Instances
data a :+: b Source
The "sum" encodes 2 constructor alternatives. An analogous standard Haskell type is Either a b.
L aLeft alternative
R bRight alternative
show/hide Instances
(Generic g, Rep g a, Rep g b) => Rep g (a :+: b)
(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)
data a :*: b Source
The "product" encodes 2 constructor arguments. An analogous standard Haskell type is (a, b).
a :*: bA pair of arguments
show/hide Instances
(Generic g, Rep g a, Rep g b) => Rep g (a :*: b)
(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)
Embedding-Projection Pair
A pair of a function and its inverse form the isomorphism between a datatype and its structure representation.
data EP d r Source
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.
from :: d -> rEmbed a datatype into its representation.
to :: r -> dProject datatype from its representation.
Constructor Description
A description of the syntax of each constructor provides useful auxiliary information for some generic functions.
data ConDescr Source

A constructor description containing useful meta-information about the syntax used in the data declaration. This is particularly useful in Read and Show but may also be helpful in other generic functions.

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.

conName :: StringName of the constructor. If it is infix, don't provide parentheses.
conArity :: IntArity or number of arguments.
conLabels :: [String]A list of labels used in record syntax. They must be declared in the same order as the data declaration. The list should be empty if the constructor is not a record.
conFixity :: FixityInfix or not, associativity, precedence.
show/hide Instances
data ConType Source
The constructor type used in Read and Show to determine how to parse or print the constructor.
ConStdStandard (function-type, nonfix)
ConRec [String]Record-style (nonfix or infix)
ConIfx StringInfix (no record syntax)
show/hide Instances
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.
data Fixity Source
An identifier's fixity, associativity, and precedence. If not infix (Nonfix), the associativity and precedence of the identifier is the same as function application. If infix, the associativity is indicated by the constructor and the precedence is an argument to it.
NonfixNot infix. Associativity and precedence are the same as function application.
Infix PrecNon-associative infix with precedence.
Infixl PrecLeft-associative infix with precedence.
Infixr PrecRight-associative Infix with precedence.
show/hide Instances
prec :: Fixity -> PrecSource
Get the precedence of a fixity value.
maxPrec :: PrecSource
Maximum precedence: 11
appPrec :: PrecSource
Precedence for function application: 10
recPrec :: PrecSource
Precedence for record construction: 11
Produced by Haddock version 2.4.2