instant-generics-0.3.3: Generic programming library with a sum of products view

Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org

Generics.Instant.Base

Description

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'

Synopsis

Documentation

data Z Source

data U Source

Constructors

U 

Instances

Read U 
Show U 
Representable U 
HasRec U 
Empty U 
GShow' U 
GEq' U 

data a :+: b Source

Constructors

L a 
R b 

Instances

(Read a, Read b) => Read (:+: a b) 
(Show a, Show b) => Show (:+: a b) 
(Representable a, Representable b) => Representable (:+: a b) 
(HasRec a, HasRec b) => HasRec (:+: a b) 
(HasRec a, Empty a, Empty b) => Empty (:+: a b) 
(GShow' a, GShow' b) => GShow' (:+: a b) 
(GEq' a, GEq' b) => GEq' (:+: a b) 

data a :*: b Source

Constructors

a :*: b 

Instances

(Read a, Read b) => Read (:*: a b) 
(Show a, Show b) => Show (:*: a b) 
(Representable a, Representable b) => Representable (:*: a b) 
(HasRec a, HasRec b) => HasRec (:*: a b) 
(Empty a, Empty b) => Empty (:*: a b) 
(GShow' a, GShow' b) => GShow' (:*: a b) 
(GEq' a, GEq' b) => GEq' (:*: a b) 

data CEq c p q a whereSource

Constructors

C :: a -> CEq c p p a 

Instances

Read a => Read (CEq c p p a) 
Show a => Show (CEq c p q a) 
Representable a => Representable (CEq c p q a) 
HasRec a => HasRec (CEq c p q a) 
Empty a => Empty (CEq c p p a) 
(GShow' a, Constructor c) => GShow' (CEq c p q a) 
GEq' a => GEq' (CEq c p q a) 

type C c a = CEq c () () aSource

data Var a Source

Constructors

Var a 

Instances

Read a => Read (Var a) 
Show a => Show (Var a) 
Representable a => Representable (Var a) 
HasRec (Var a) 
Empty a => Empty (Var a) 
GShow a => GShow' (Var a) 
GEq a => GEq' (Var a) 

data Rec a Source

Constructors

Rec a 

Instances

Read a => Read (Rec a) 
Show a => Show (Rec a) 
Representable a => Representable (Rec a) 
HasRec (Rec a) 
Empty a => Empty (Rec a) 
GShow a => GShow' (Rec a) 
GEq a => GEq' (Rec a) 

class Constructor c whereSource

Class for datatypes that represent data constructors. For non-symbolic constructors, only conName has to be defined.

Methods

conName :: t c p q a -> StringSource

conFixity :: t c p q a -> FixitySource

conIsRecord :: t c p q a -> BoolSource

Instances

Constructor Tuple_Pair_ 
Constructor Maybe_Just_ 
Constructor Maybe_Nothing_ 
Constructor List_Cons_ 
Constructor List_Nil_ 

data Fixity Source

Datatype to represent the fixity of a constructor. An infix declaration directly corresponds to an application of Infix.

Constructors

Prefix 
Infix Associativity Int 

data Associativity Source

Datatype to represent the associativy of a constructor.

type family X c n a Source

data Ze Source

data Su Source