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

Safe HaskellNone
LanguageHaskell2010

Data.NamedSOP.Map

Description

 
Synopsis

Documentation

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

A depedently-typed product, or map. The following are roughly equivalent:

type A = NMap '[ "a" ':-> Int, "b" ':-> Bool ]
data A = A { a :: Int, b :: Bool }

Constructors

NMapEmpty :: NMap '[] 
NMapExt :: forall k v xs. v -> NMap xs -> NMap ((k :-> v) ': xs) 
Instances
ShowMap xs => Show (NMap xs) Source # 
Instance details

Defined in Data.NamedSOP.Map

Methods

showsPrec :: Int -> NMap xs -> ShowS #

show :: NMap xs -> String #

showList :: [NMap xs] -> ShowS #

unionMap :: forall xs ys. (SingI xs, SingI ys) => (NMap xs, NMap ys) -> NMap (Union xs ys) Source #

Combine two NMaps in a way such that the original ordering of their fields doesn't matter; no matter how you combine smaller maps to create a large one, you are guaranteed to have a sorted NMap when you finish.

NMaps form a commutative monoid under unionMap, with NMapEmpty as the identity.

This function takes a tuple as an argument so that it is symmetric with ununionMap.

ununionMap :: forall xs ys. (SingI xs, SingI ys) => NMap (Union xs ys) -> (NMap xs, NMap ys) Source #

Split a sorted NMap into two arbitrary (and potentially unsorted) submaps. Conveniently select the submaps to split into using -XTypeApplications.

>>> m :: NMap '[ "a" ':-> Int, "b" ':-> Bool, "c" ':-> String ]
>>> m = NMapExt 1 (NMapExt True (NMapExt "hello" NMapEmpty))
>>> ununionMap @'[ "b" ':-> Bool, "a" ':-> Int ] @'[ "c" ':-> String ] m
({ b :-> True, a :-> 1 },{ c :-> "hello" })