Generics.SOP.Metadata

generics-sop-0.2.1.0: Generic Programming using True Sums of Products

Safe Haskell | None
Language | Haskell2010

Generics.SOP.Metadata

Contents

- re-exports

Description

Metadata about what a datatype looks like

In `generics-sop`, the metadata is completely independent of the main universe. Many generic functions will use this metadata, but other don't, and yet others might need completely different metadata.

This module defines a datatype to represent standard metadata, i.e., names of the datatype, its constructors, and possibly its record selectors. Metadata descriptions are in general GADTs indexed by the code of the datatype they're associated with, so matching on the metadata will reveal information about the shape of the datatype.

Synopsis

- data DatatypeInfo :: [[*]] -> * where
  - ADT :: ModuleName -> DatatypeName -> NP ConstructorInfo xss -> DatatypeInfo xss
  - Newtype :: ModuleName -> DatatypeName -> ConstructorInfo `[x]` -> DatatypeInfo `[`[x]`]`
- data ConstructorInfo :: [*] -> * where
  - Constructor :: SListI xs => ConstructorName -> ConstructorInfo xs
  - Infix :: ConstructorName -> Associativity -> Fixity -> ConstructorInfo `[x, y]`
  - Record :: SListI xs => ConstructorName -> NP FieldInfo xs -> ConstructorInfo xs
- data FieldInfo :: * -> * where
  - FieldInfo :: FieldName -> FieldInfo a
- type DatatypeName = String
- type ModuleName = String
- type ConstructorName = String
- type FieldName = String
- type Fixity = Int
- data Associativity :: *
  - = LeftAssociative
  - | RightAssociative
  - | NotAssociative

# Documentation

data DatatypeInfo :: [[*]] -> * where

Metadata for a datatype.

A value of type ``DatatypeInfo` c` contains the information about a datatype that is not contained in ``Code` c`. This information consists primarily of the names of the datatype, its constructors, and possibly its record selectors.

The constructor indicates whether the datatype has been declared using `newtype` or not.

Constructors

ADT :: ModuleName -> DatatypeName -> NP ConstructorInfo xss -> DatatypeInfo xss |
Newtype :: ModuleName -> DatatypeName -> ConstructorInfo `[x]` -> DatatypeInfo `[`[x]`]` |

Instances

All [*] (Compose * [*] Eq ConstructorInfo) xs => Eq (DatatypeInfo xs) |
(All [*] (Compose * [*] Eq ConstructorInfo) xs, All [*] (Compose * [*] Ord ConstructorInfo) xs) => Ord (DatatypeInfo xs) |
All [*] (Compose * [*] Show ConstructorInfo) xs => Show (DatatypeInfo xs) |

data ConstructorInfo :: [*] -> * where

Metadata for a single constructors.

This is indexed by the product structure of the constructor components.

Constructors

Constructor :: SListI xs => ConstructorName -> ConstructorInfo xs |
Infix :: ConstructorName -> Associativity -> Fixity -> ConstructorInfo `[x, y]` |
Record :: SListI xs => ConstructorName -> NP FieldInfo xs -> ConstructorInfo xs |

Instances

All * (Compose * * Eq FieldInfo) xs => Eq (ConstructorInfo xs) |
(All * (Compose * * Eq FieldInfo) xs, All * (Compose * * Ord FieldInfo) xs) => Ord (ConstructorInfo xs) |
All * (Compose * * Show FieldInfo) xs => Show (ConstructorInfo xs) |

data FieldInfo :: * -> * where

For records, this functor maps the component to its selector name.

Constructors

FieldInfo :: FieldName -> FieldInfo a |

Instances

Functor FieldInfo |
Eq (FieldInfo a) |
Ord (FieldInfo a) |
Show (FieldInfo a) |

type DatatypeName = String

The name of a datatype.

type ModuleName = String

The name of a module.

type ConstructorName = String

The name of a data constructor.

type FieldName = String

The name of a field / record selector.

type Fixity = Int

The fixity of an infix constructor.

# re-exports

data Associativity :: *

Datatype to represent the associativity of a constructor

Constructors

LeftAssociative |
RightAssociative |
NotAssociative |

Instances

Eq Associativity |
Ord Associativity |
Read Associativity |
Show Associativity |
Generic Associativity |
type Rep Associativity = D1 D1Associativity ((:+:) (C1 C1_0Associativity U1) ((:+:) (C1 C1_1Associativity U1) (C1 C1_2Associativity U1))) |