freer-effects-0.3.0.1: Implementation of effect system for Haskell.

Copyright(c) 2016 Allele Dev; 2017 Ixperta Solutions s.r.o.
LicenseBSD3
Maintainerixcom-core@ixperta.com
Stabilityexperimental
PortabilityGHC specific language extensions.
Safe HaskellNone
LanguageHaskell2010

Data.OpenUnion

Contents

Description

This implementation relies on _closed_ type families added to GHC 7.8. It has NO overlapping instances and NO Typeable. Alas, the absence of Typeable means the projections and injections generally take linear time. The code illustrate how to use closed type families to disambiguate otherwise overlapping instances.

The data constructors of Union are not exported. Essentially, the nested Either data type.

Using http://okmij.org/ftp/Haskell/extensible/OpenUnion41.hs as a starting point.

Synopsis

Open Union

data Union r a Source #

Open union is a strong sum (existential with an evidence).

Open Union Operations

decomp :: Union (t ': r) a -> Either (Union r a) (t a) Source #

Orthogonal decomposition of a Union (t ': r) :: * -> *. Right value is returned if the Union (t ': r) :: * -> * contains t :: * -> *, and Left when it doesn't. Notice that Left value contains Union r :: * -> *, i.e. it can not contain t :: * -> *.

O(1)

weaken :: Union r a -> Union (any ': r) a Source #

Inject whole Union r into a weaker Union (any ': r) that has one more summand.

O(1)

extract :: Union '[t] a -> t a Source #

Specialised version of 'prj'\/'decomp' that works on an Union '[t] :: * -> * which contains only one specific summand. Hence the absence of Maybe, and Either.

O(1)

Open Union Membership Constraints

class FindElem t r => Member t r where Source #

This type class is used for two following purposes:

  • As a Constraint it guarantees that t :: * -> * is a member of a type-list r :: [* -> *].
  • Provides a way how to inject/project t :: * -> * into/from a Union, respectively.

Following law has to hold:

prj . inj === Just

Minimal complete definition

inj, prj

Methods

inj :: t a -> Union r a Source #

Takes a request of type t :: * -> *, and injects it into the Union.

O(1)

prj :: Union r a -> Maybe (t a) Source #

Project a value of type Union (t ': r) :: * -> * into a possible summand of the type t :: * -> *. Nothing means that t :: * -> * is not the value stored in the Union (t ': r) :: * -> *.

O(1)

Instances

FindElem t r => Member t r Source # 

Methods

inj :: t a -> Union * r a Source #

prj :: Union * r a -> Maybe (t a) Source #

type family Members m r :: Constraint where ... Source #

Equations

Members (t ': c) r = (Member t r, Members c r) 
Members '[] r = ()