| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.NamedSOP.Sum
Description
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
Constructors
| NSumThis :: v -> NSum ((k :-> v) ': xs) | |
| NSumThat :: forall x xs. NSum xs -> NSum (x ': xs) |
unionSum :: forall xs ys. (SingI xs, SingI ys) => Either (NSum xs) (NSum ys) -> NSum (Union xs ys) Source #
Combine two NSums. 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.
NSums 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.>>>ununionSum @'[ "B" ':-> Bool, "A" ':-> Int ] @'[ "C" ':-> String ] sLeft (B :-> True)
module Data.NamedSOP.Type