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

Portabilitynon-portable
Stabilityexperimental
Maintainergenerics@haskell.org
Safe HaskellSafe-Inferred

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 
GEnum 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) 
(GEnum f, GEnum g) => GEnum (:+: f g) 

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) 
(GEnum f, GEnum g) => GEnum (:*: f g) 

data CEq c p q a whereSource

Constructors

C :: a -> CEq c p p a 

Instances

Read a => Read (CEq k k1 c p p a) 
Show a => Show (CEq k k1 c p q a) 
Representable a => Representable (CEq * * c p q a) 
HasRec a => HasRec (CEq k k1 c p q a) 
Empty a => Empty (CEq k k1 c p p a) 
GEnum (CEq k k1 c p q a) 
GEnum a => GEnum (CEq k k1 c p p 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) 
GEnum a => GEnum (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) 
GEnum a => GEnum (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

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 

Instances

Eq Fixity 
Ord Fixity 
Read Fixity 
Show Fixity 
Lift Fixity 

data Associativity Source

Datatype to represent the associativy of a constructor.

class Representable a whereSource

Associated Types

type Rep a Source

Methods

to :: Rep a -> aSource

from :: a -> Rep aSource

type family X c n a :: k2Source

data Nat Source

Constructors

Ze 
Su Nat