effect-handlers-0.1.0.0

Safe HaskellNone
LanguageHaskell2010

Data.Union

Description

This module provides an open union of functors.

Synopsis

Documentation

data Union r a

Union is an open sum of functors A value of type Union r a is a value f a for some f that is a member of the r list Since direct construction is not safe you have to use inj to create a value.

Instances

class Member f r

The Member type clas denotes that f is a member of type list r

Instances

Member x t => Member x ((:) (* -> *) h t) 
Member h ((:) (* -> *) h t) 

inj :: (Typeable f, Functor f, Member f r) => f a -> Union r a

Smart constructor for Union. Injects the functor into any union of which the said functor is a member. Please note that only the type constructor need be a Typeable.

prj :: (Typeable f, Member f r) => Union r a -> Maybe (f a)

Project a Union into a specific functor.

decomp :: Typeable f => Union (f : r) a -> Either (f a) (Union r a)

Decompose a Union. Similar to prj but gives you a Union instance without the functor f in type if projection fails.

trivial :: Typeable f => Union `[f]` a -> f a

A Union of one functor can only be that. Safe cast.