open-union-0.1.0.1: Extensible, type-safe unions.

Safe HaskellNone
LanguageHaskell98

Data.OpenUnion

Description

Flexible, type-safe open unions.

Synopsis

Documentation

data Union s Source

The Union type - the phantom parameter s is a list of types denoting what this Union might contain. The value contained is one of those types.

class s :< s' Source

There exists a s :< s' instance if every type in the list s can be lifted to s'.

Instances

([] *) :< s 
((:<) s s', (:<) ((:) * a ([] *)) s', Typeable * a) => ((:) * a s) :< s' 
((:<) s s', Typeable * a) => ((:) * a s) :< ((:) * a s') 

type family s :\ a Source

Remove a type from anywhere in the list.

Equations

[] :\ a = [] 
(a : s) :\ a = s :\ a 
(a' : s) :\ a = a' : (s :\ a) 

(@>) :: Typeable a => (a -> b) -> (Union (s :\ a) -> b) -> Union s -> b infixr 2 Source

restrict in right-fixable style.

liftUnion :: (Typeable a, `[a]` :< s) => a -> Union s Source

reUnion :: s :< s' => Union s -> Union s' Source

Generalize a Union.

restrict :: Typeable a => Union s -> Either (Union (s :\ a)) a Source

Narrow down a Union.

typesExhausted :: Union [] -> a Source

Use this in places where all the Unioned options have been exhausted.