effect-handlers-0.1.0.8: A library for writing extensible algebraic effects and handlers. Similar to extensible-effects but with deep handlers.

Safe HaskellNone
LanguageHaskell2010

Data.Union

Description

This module provides an open union of functors.

Synopsis

Documentation

data Union r a Source #

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

Functor (Union r) Source # 

Methods

fmap :: (a -> b) -> Union r a -> Union r b #

(<$) :: a -> Union r b -> Union r a #

class Member f r Source #

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

Instances

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

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

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) Source #

Project a Union into a specific functor.

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

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 Source #

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