GHC.Generics

base-4.6.0.1: Basic libraries

Safe Haskell | Trustworthy

GHC.Generics

Contents

- Generic representation types
  - Synonyms for convenience
- Meta-information
- Generic type classes

Synopsis

- data V1 p
- data U1 p = U1
- newtype Par1 p = Par1 {
  - unPar1 :: p
  }
- newtype Rec1 f p = Rec1 {
  - unRec1 :: f p
  }
- newtype K1 i c p = K1 {
  - unK1 :: c
  }
- newtype M1 i c f p = M1 {
  - unM1 :: f p
  }
- data (f :+: g) p
  - = L1 (f p)
  - | R1 (g p)
- data (f :*: g) p = (f p) :*: (g p)
- newtype (f :.: g) p = Comp1 {
  - unComp1 :: f (g p)
  }
- type Rec0 = K1 R
- type Par0 = K1 P
- data R
- data P
- type D1 = M1 D
- type C1 = M1 C
- type S1 = M1 S
- data D
- data C
- data S
- class Datatype d where
  - datatypeName :: t d (f :: * -> *) a -> [Char]
  - moduleName :: t d (f :: * -> *) a -> [Char]
- class Constructor c where
  - conName :: t c (f :: * -> *) a -> [Char]
  - conFixity :: t c (f :: * -> *) a -> Fixity
  - conIsRecord :: t c (f :: * -> *) a -> Bool
- class Selector s where
  - selName :: t s (f :: * -> *) a -> [Char]
- data NoSelector
- data Fixity
  - = Prefix
  - | Infix Associativity Int
- data Associativity
  - = LeftAssociative
  - | RightAssociative
  - | NotAssociative
- data Arity
  - = NoArity
  - | Arity Int
- prec :: Fixity -> Int
- class Generic a where
  - type Rep a :: * -> *
  - from :: a -> Rep a x
  - to :: Rep a x -> a
- class Generic1 f where
  - type Rep1 f :: * -> *
  - from1 :: f a -> Rep1 f a
  - to1 :: Rep1 f a -> f a

# Generic representation types

data V1 p

Void: used for datatypes without constructors

data U1 p

Unit: used for constructors without arguments

Constructors

U1 |

newtype Par1 p

Used for marking occurrences of the parameter

Constructors

Par1 |
Fields unPar1 :: p

newtype Rec1 f p

Recursive calls of kind * -> *

Constructors

Rec1 |
Fields unRec1 :: f p

newtype K1 i c p

Constants, additional parameters and recursion of kind *

Constructors

K1 |
Fields unK1 :: c

newtype M1 i c f p

Meta-information (constructor names, etc.)

Constructors

M1 |
Fields unM1 :: f p

data (f :+: g) p

Sums: encode choice between constructors

Constructors

L1 (f p) |
R1 (g p) |

data (f :*: g) p

Products: encode multiple arguments to constructors

Constructors

(f p) :*: (g p) |

newtype (f :.: g) p

Composition of functors

Constructors

Comp1 |
Fields unComp1 :: f (g p)

## Synonyms for convenience

type Rec0 = K1 R

Type synonym for encoding recursion (of kind *)

type Par0 = K1 P

Deprecated: Par0 is no longer used; use Rec0 instead

Type synonym for encoding parameters (other than the last)

data R

Tag for K1: recursion (of kind *)

data P

Deprecated: P is no longer used; use R instead

Tag for K1: parameters (other than the last)

type D1 = M1 D

Type synonym for encoding meta-information for datatypes

type C1 = M1 C

Type synonym for encoding meta-information for constructors

type S1 = M1 S

Type synonym for encoding meta-information for record selectors

data D

Tag for M1: datatype

data C

Tag for M1: constructor

data S

Tag for M1: record selector

# Meta-information

class Datatype d where

Class for datatypes that represent datatypes

Methods

datatypeName :: t d (f :: * -> *) a -> [Char]

The name of the datatype (unqualified)

moduleName :: t d (f :: * -> *) a -> [Char]

The fully-qualified name of the module where the type is declared

class Constructor c where

Class for datatypes that represent data constructors

Methods

conName :: t c (f :: * -> *) a -> [Char]

The name of the constructor

conFixity :: t c (f :: * -> *) a -> Fixity

The fixity of the constructor

conIsRecord :: t c (f :: * -> *) a -> Bool

Marks if this constructor is a record

class Selector s where

Class for datatypes that represent records

Methods

selName :: t s (f :: * -> *) a -> [Char]

The name of the selector

Instances

Selector NoSelector |

data NoSelector

Used for constructor fields without a name

Instances

Selector NoSelector |

data Fixity

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 |

data Associativity

Datatype to represent the associativity of a constructor

Constructors

LeftAssociative |
RightAssociative |
NotAssociative |

Instances

Eq Associativity |
Ord Associativity |
Read Associativity |
Show Associativity |

data Arity

Datatype to represent the arity of a tuple.

Constructors

NoArity |
Arity Int |

Instances

Eq Arity |
Ord Arity |
Read Arity |
Show Arity |

prec :: Fixity -> Int

Get the precedence of a fixity value.

# Generic type classes

class Generic a where

Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.

Associated Types

type Rep a :: * -> *

Generic representation type

Methods

from :: a -> Rep a x

Convert from the datatype to its representation

to :: Rep a x -> a

Convert from the representation to the datatype

Instances

Generic Bool |
Generic Char |
Generic Double |
Generic Float |
Generic Int |
Generic Ordering |
Generic () |
Generic [a] |
Generic (Maybe a) |
Generic (Either a b) |
Generic (a, b) |
Generic (a, b, c) |
Generic (a, b, c, d) |
Generic (a, b, c, d, e) |
Generic (a, b, c, d, e, f) |
Generic (a, b, c, d, e, f, g) |

class Generic1 f where

Representable types of kind * -> *. This class is derivable in GHC with the DeriveGeneric flag on.

Associated Types

type Rep1 f :: * -> *

Generic representation type

Methods

from1 :: f a -> Rep1 f a

Convert from the datatype to its representation

to1 :: Rep1 f a -> f a

Convert from the representation to the datatype

Instances

Generic1 [] |
Generic1 Maybe |
Generic1 (Either a) |
Generic1 ((,) a) |
Generic1 ((,,) a b) |
Generic1 ((,,,) a b c) |
Generic1 ((,,,,) a b c d) |
Generic1 ((,,,,,) a b c d e) |
Generic1 ((,,,,,,) a b c d e f) |