Copyright | (c) 2016 Allele Dev; 2017 Ixperta Solutions s.r.o. |
---|---|
License | BSD3 |
Maintainer | ixcom-core@ixperta.com |
Stability | experimental |
Portability | GHC specific language extensions. |
Safe Haskell | None |
Language | Haskell2010 |
These are internal definitions and should be used with caution. There are no guarantees that the API of this module will be preserved between minor versions of this package.
Open unions (type-indexed co-products, i.e. type-indexed sums) for extensible effects All operations are constant-time.
Based on OpenUnion51.hs.
Type-list r :: [* -> *]
of open union components is a small Universe.
Therefore, we can use a Typeable
-like evidence in that universe. In our
case a simple index of an element in the type-list is sufficient
substitution for Typeable
.
- data Union r a where
- unsafeInj :: Word -> t a -> Union r a
- unsafePrj :: Word -> Union r a -> Maybe (t a)
- newtype P t r = P {}
- class FindElem t r where
- class FindElem t r => Member t r where
- decomp :: Union (t ': r) a -> Either (Union r a) (t a)
- decomp0 :: Union '[t] a -> Either (Union '[] a) (t a)
- extract :: Union '[t] a -> t a
- weaken :: Union r a -> Union (any ': r) a
Documentation
Open union is a strong sum (existential with an evidence).
unsafePrj :: Word -> Union r a -> Maybe (t a) Source #
Project a value of type
into a possible
summand of the type Union
(t ': r) :: * -> *t :: * -> *
. Nothing
means that t :: * -> *
is not
the value stored in the
.Union
(t ': r) :: * -> *
It is assumed that summand is stored in the Union
when the Word
value is
the same value as is stored in the Union
.
This function is unsafe.
O(1)
Represents position of element t :: * -> *
in a type list
r :: [* -> *]
.
class FindElem t r where Source #
Find an index of an element t :: * -> *
in a type list r :: [* -> *]
.
The element must exist.
This is essentially a compile-time computation without run-time overhead.
Position of the element t :: * -> *
in a type list r :: [* -> *]
.
Position is computed during compilation, i.e. there is no run-time overhead.
O(1)
class FindElem t r => Member t r where Source #
This type class is used for two following purposes:
- As a
Constraint
it guarantees thatt :: * -> *
is a member of a type-listr :: [* -> *]
. - Provides a way how to inject/project
t :: * -> *
into/from aUnion
, respectively.
Following law has to hold:
prj
.inj
===Just