Generics.SOP.Dict

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

Safe Haskell | None
Language | Haskell2010

Generics.SOP.Dict

Description

Explicit dictionaries.

When working with compound constraints such as constructed using `All` or `All2`, GHC cannot always prove automatically what one would expect to hold.

This module provides a way of explicitly proving conversions between such constraints to GHC. Such conversions still have to be manually applied.

This module is new and experimental in generics-sop 0.2. It is therefore not yet exported via the main module and has to be imported explicitly. Its interface is to be considered even less stable than that of the rest of the library. Feedback is very welcome though.

Synopsis

- data Dict c a where
  - Dict :: c a => Dict c a
- pureAll :: SListI xs => Dict (All Top) xs
- pureAll2 :: All SListI xss => Dict (All2 Top) xss
- mapAll :: forall c d xs. (forall a. Dict c a -> Dict d a) -> Dict (All c) xs -> Dict (All d) xs
- mapAll2 :: forall c d xss. (forall a. Dict c a -> Dict d a) -> Dict (All2 c) xss -> Dict (All2 d) xss
- zipAll :: Dict (All c) xs -> Dict (All d) xs -> Dict (All (c `And` d)) xs
- zipAll2 :: All SListI xss => Dict (All2 c) xss -> Dict (All2 d) xss -> Dict (All2 (c `And` d)) xss
- unAll_NP :: forall c xs. Dict (All c) xs -> NP (Dict c) xs
- unAll_POP :: forall c xss. Dict (All2 c) xss -> POP (Dict c) xss
- all_NP :: NP (Dict c) xs -> Dict (All c) xs
- all_POP :: SListI xss => POP (Dict c) xss -> Dict (All2 c) xss
- unAll2 :: Dict (All2 c) xss -> Dict (All (All c)) xss
- all2 :: Dict (All (All c)) xss -> Dict (All2 c) xss
- withDict :: Dict c a -> (c a => r) -> r

# Documentation

data Dict c a where #

An explicit dictionary carrying evidence of a class constraint.

The constraint parameter is separated into a second argument so that ``Dict` c` is of the correct kind to be used directly as a parameter to e.g. `NP`.

Since: 0.2

Constructors

Dict :: c a => Dict c a |

pureAll :: SListI xs => Dict (All Top) xs #

A proof that the trivial constraint holds over all type-level lists.

Since: 0.2

pureAll2 :: All SListI xss => Dict (All2 Top) xss #

A proof that the trivial constraint holds over all type-level lists of lists.

Since: 0.2

mapAll :: forall c d xs. (forall a. Dict c a -> Dict d a) -> Dict (All c) xs -> Dict (All d) xs #

Lifts a dictionary conversion over a type-level list.

Since: 0.2

mapAll2 :: forall c d xss. (forall a. Dict c a -> Dict d a) -> Dict (All2 c) xss -> Dict (All2 d) xss #

Lifts a dictionary conversion over a type-level list of lists.

Since: 0.2

zipAll :: Dict (All c) xs -> Dict (All d) xs -> Dict (All (c `And` d)) xs #

If two constraints `c` and `d` hold over a type-level list `xs`, then the combination of both constraints holds over that list.

Since: 0.2

zipAll2 :: All SListI xss => Dict (All2 c) xss -> Dict (All2 d) xss -> Dict (All2 (c `And` d)) xss #

If two constraints `c` and `d` hold over a type-level list of lists `xss`, then the combination of both constraints holds over that list of lists.

Since: 0.2

unAll_NP :: forall c xs. Dict (All c) xs -> NP (Dict c) xs #

If we have a constraint `c` that holds over a type-level list `xs`, we can create a product containing proofs that each individual list element satisfies `c`.

Since: 0.2

unAll_POP :: forall c xss. Dict (All2 c) xss -> POP (Dict c) xss #

If we have a constraint `c` that holds over a type-level list of lists `xss`, we can create a product of products containing proofs that all the inner elements satisfy `c`.

Since: 0.2

all_NP :: NP (Dict c) xs -> Dict (All c) xs #

If we have a product containing proofs that each element of `xs` satisfies `c`, then 'All c' holds for `xs`.

Since: 0.2

all_POP :: SListI xss => POP (Dict c) xss -> Dict (All2 c) xss #

If we have a product of products containing proofs that each inner element of `xss` satisfies `c`, then 'All2 c' holds for `xss`.

Since: 0.2

unAll2 :: Dict (All2 c) xss -> Dict (All (All c)) xss #

The constraint 'All2 c' is convertible to 'All (All c)'.

Since: 0.2

all2 :: Dict (All (All c)) xss -> Dict (All2 c) xss #

The constraint 'All (All c)' is convertible to 'All2 c'.

Since: 0.2

withDict :: Dict c a -> (c a => r) -> r #

If we have an explicit dictionary, we can unwrap it and pass a function that makes use of it.

Since: 0.2