sop-core-0.5.0.2: True Sums of Products

Safe Haskell | None
Language | Haskell2010

Data.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 remains somewhat experimental. It is therefore not exported via the main module and has to be imported explicitly.

Synopsis

- data Dict (c :: k -> Constraint) (a :: k) where
  - Dict :: forall {k} (c :: k -> Constraint) (a :: k). c a => Dict c a
- pureAll :: forall {k} (xs :: [k]). SListI xs => Dict (All (Top :: k -> Constraint)) xs
- pureAll2 :: forall {k} (xss :: [[k]]). All (SListI :: [k] -> Constraint) xss => Dict (All2 (Top :: k -> Constraint)) xss
- mapAll :: forall {k} (c :: k -> Constraint) (d :: k -> Constraint) (xs :: [k]). (forall (a :: k). Dict c a -> Dict d a) -> Dict (All c) xs -> Dict (All d) xs
- mapAll2 :: forall {k} (c :: k -> Constraint) (d :: k -> Constraint) (xss :: [[k]]). (forall (a :: k). Dict c a -> Dict d a) -> Dict (All2 c) xss -> Dict (All2 d) xss
- zipAll :: forall {k} (c :: k -> Constraint) (xs :: [k]) (d :: k -> Constraint). Dict (All c) xs -> Dict (All d) xs -> Dict (All (And c d)) xs
- zipAll2 :: forall {k} (xss :: [[k]]) (c :: k -> Constraint) (d :: k -> Constraint). All (SListI :: [k] -> Constraint) xss => Dict (All2 c) xss -> Dict (All2 d) xss -> Dict (All2 (And c d)) xss
- unAll_NP :: forall {k} (c :: k -> Constraint) (xs :: [k]). Dict (All c) xs -> NP (Dict c) xs
- unAll_POP :: forall {k} (c :: k -> Constraint) (xss :: [[k]]). Dict (All2 c) xss -> POP (Dict c) xss
- all_NP :: forall {k} (c :: k -> Constraint) (xs :: [k]). NP (Dict c) xs -> Dict (All c) xs
- all_POP :: forall {k} (xss :: [[k]]) (c :: k -> Constraint). SListI xss => POP (Dict c) xss -> Dict (All2 c) xss
- unAll2 :: forall {k} (c :: k -> Constraint) (xss :: [[k]]). Dict (All2 c) xss -> Dict (All (All c)) xss
- all2 :: forall {k} (c :: k -> Constraint) (xss :: [[k]]). Dict (All (All c)) xss -> Dict (All2 c) xss
- withDict :: forall {k} c (a :: k) r. Dict c a -> (c a => r) -> r
- hdicts :: forall {k} {l} h (c :: k -> Constraint) (xs :: l). (AllN h c xs, HPure h) => h (Dict c) xs

# Documentation

data Dict (c :: k -> Constraint) (a :: k) 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 :: forall {k} (c :: k -> Constraint) (a :: k). c a => Dict c a |

#### Instances

Instances details

Show (Dict c a) # |
Instance details Defined in Data.SOP.Dict Methods showsPrec :: Int -> Dict c a -> ShowS # show :: Dict c a -> String # showList :: [Dict c a] -> ShowS #

pureAll :: forall {k} (xs :: [k]). SListI xs => Dict (All (Top :: k -> Constraint)) xs #

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

Since: 0.2

pureAll2 :: forall {k} (xss :: [[k]]). All (SListI :: [k] -> Constraint) xss => Dict (All2 (Top :: k -> Constraint)) xss #

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

Since: 0.2

mapAll :: forall {k} (c :: k -> Constraint) (d :: k -> Constraint) (xs :: [k]). (forall (a :: k). 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 {k} (c :: k -> Constraint) (d :: k -> Constraint) (xss :: [[k]]). (forall (a :: k). 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 :: forall {k} (c :: k -> Constraint) (xs :: [k]) (d :: k -> Constraint). Dict (All c) xs -> Dict (All d) xs -> Dict (All (And c 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 :: forall {k} (xss :: [[k]]) (c :: k -> Constraint) (d :: k -> Constraint). All (SListI :: [k] -> Constraint) xss => Dict (All2 c) xss -> Dict (All2 d) xss -> Dict (All2 (And c 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 {k} (c :: k -> Constraint) (xs :: [k]). 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 {k} (c :: k -> Constraint) (xss :: [[k]]). 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 :: forall {k} (c :: k -> Constraint) (xs :: [k]). 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 :: forall {k} (xss :: [[k]]) (c :: k -> Constraint). 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 :: forall {k} (c :: k -> Constraint) (xss :: [[k]]). Dict (All2 c) xss -> Dict (All (All c)) xss #

Deprecated: 'All2 c' is now a synonym of 'All (All c)'

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

Since: 0.2

all2 :: forall {k} (c :: k -> Constraint) (xss :: [[k]]). Dict (All (All c)) xss -> Dict (All2 c) xss #

Deprecated: 'All2 c' is now a synonym of 'All (All c)'

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

Since: 0.2

withDict :: forall {k} c (a :: k) r. 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

hdicts :: forall {k} {l} h (c :: k -> Constraint) (xs :: l). (AllN h c xs, HPure h) => h (Dict c) xs #

A structure of dictionaries.

Since: 0.2.3.0