named-sop-0.1.0.0: Dependently-typed sums and products, tagged by field name

Safe HaskellNone
LanguageHaskell2010

Data.NamedSOP.Sum

Description

 
Synopsis

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) 
Instances
(KnownSymbol k, Show v, Show (NSum xs)) => Show (NSum ((k :-> v) ': xs)) Source # 
Instance details

Defined in Data.NamedSOP.Sum

Methods

showsPrec :: Int -> NSum ((k :-> v) ': xs) -> ShowS #

show :: NSum ((k :-> v) ': xs) -> String #

showList :: [NSum ((k :-> v) ': xs)] -> ShowS #

Show (NSum ([] :: [Mapping Symbol Type])) Source # 
Instance details

Defined in Data.NamedSOP.Sum

Methods

showsPrec :: Int -> NSum [] -> ShowS #

show :: NSum [] -> String #

showList :: [NSum []] -> ShowS #

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 ] s
Left (B :-> True)