Generics.SOP.Sing

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

Safe Haskell | Safe
Language | Haskell2010

Generics.SOP.Sing

Contents

- Singletons
  - Shape of type-level lists

Description

Singleton types corresponding to type-level data structures.

The implementation is similar, but subtly different to that of the `singletons` package. See the "True Sums of Products" paper for details.

Synopsis

- data SList :: [k] -> * where
  - SNil :: SList `[]`
  - SCons :: SListI xs => SList (x : xs)
- class SListI xs where
  - sList :: SList xs
- type Sing = SList
- class SListI xs => SingI xs where
  - sing :: Sing xs
- data Shape :: [k] -> * where
  - ShapeNil :: Shape `[]`
  - ShapeCons :: SListI xs => Shape xs -> Shape (x : xs)
- shape :: forall xs. SListI xs => Shape xs
- lengthSList :: forall xs proxy. SListI xs => proxy xs -> Int
- lengthSing :: SListI xs => proxy xs -> Int

# Singletons

data SList :: [k] -> * where

Explicit singleton list.

A singleton list can be used to reveal the structure of a type-level list argument that the function is quantified over. For every type-level list `xs`, there is one non-bottom value of type ``SList` xs`.

Note that these singleton lists are polymorphic in the list elements; we do not require a singleton representation for them.

Constructors

SNil :: SList `[]` |
SCons :: SListI xs => SList (x : xs) |

Instances

Eq (SList k xs) |
Ord (SList k xs) |
Show (SList k xs) |

class SListI xs where

Implicit singleton list.

A singleton list can be used to reveal the structure of a type-level list argument that the function is quantified over.

The class `SListI` should have instances that match the constructors of `SList`.

Methods

sList :: SList xs

Get hold of the explicit singleton (that one can then pattern match on).

Instances

SListI k ([] k) |
SListI k xs => SListI k ((:) k x xs) |

type Sing = SList

Deprecated: Use `SList` instead.

Explicit singleton type.

Just provided for limited backward compatibility.

class SListI xs => SingI xs where

Deprecated: Use `SListI` instead.

General class for implicit singletons.

Just provided for limited backward compatibility.

Methods

sing :: Sing xs

Deprecated: Use `sList` instead.

## Shape of type-level lists

data Shape :: [k] -> * where

Occassionally it is useful to have an explicit, term-level, representation of type-level lists (esp because of https://ghc.haskell.org/trac/ghc/ticket/9108)

Constructors

ShapeNil :: Shape `[]` |
ShapeCons :: SListI xs => Shape xs -> Shape (x : xs) |

Instances

Eq (Shape k xs) |
Ord (Shape k xs) |
Show (Shape k xs) |

shape :: forall xs. SListI xs => Shape xs

The shape of a type-level list.

lengthSList :: forall xs proxy. SListI xs => proxy xs -> Int

The length of a type-level list.

lengthSing :: SListI xs => proxy xs -> Int

Deprecated: Use `lengthSList` instead.

Old name for `lengthSList`.