Safe Haskell | None |
---|---|

Language | Haskell2010 |

# Documentation

data NSum :: [Mapping Symbol Type] -> Type where Source #

A dependently-typed sum. The following are roughly equilvalent:

type A = NSum '[ "B" ':-> Int, "C" ':-> Bool ] data A = B Int | C Bool

unionSum :: forall xs ys. (SingI xs, SingI ys) => Either (NSum xs) (NSum ys) -> NSum (Union xs ys) Source #

Combine two `NSum`

s. This is dual to
`unionMap`

, which accepts a product of products
and returns a product; `unionSum`

accepts a sum of sums and returns
a sum. The order of fields does not matter, because they will be
sorted.

`NSum`

s form a commutative monoid under `unionSum`

, with `NSum '[]`

as the identity.

Together with `NMap`

,
`NMapEmpty`

, and `unionMap`

, it
is a semiring.

ununionSum :: forall xs ys. (SingI xs, SingI ys) => NSum (Union xs ys) -> Either (NSum xs) (NSum ys) Source #

Split a sorted `NSum`

into either of two (potentially unsorted)
subsums. Select the subsums with `-XTypeApplications`

.

`>>>`

`s :: NSum '[ "A" ':-> Int, "B" ':-> Bool, "C" ':-> String ]`

`>>>`

`s = NSumThat (NSumThis True) -- Select the "B" field.`

`>>>`

Left (B :-> True)`ununionSum @'[ "B" ':-> Bool, "A" ':-> Int ] @'[ "C" ':-> String ] s`

module Data.NamedSOP.Type