| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Union
Description
Extensible type-safe unions.
- data Union (f :: u -> *) (as :: [u]) where
- union :: (Union f as -> c) -> (f a -> c) -> Union f (a ': as) -> c
- absurdUnion :: Union f '[] -> a
- umap :: (forall a. f a -> g a) -> Union f as -> Union g as
- _This :: Prism (Union f (a ': as)) (Union f (b ': as)) (f a) (f b)
- _That :: Prism (Union f (a ': as)) (Union f (a ': bs)) (Union f as) (Union f bs)
- class i ~ RIndex a as => UElem (a :: u) (as :: [u]) (i :: Nat) where
- class is ~ RImage as bs => USubset (as :: [u]) (bs :: [u]) is where
- type OpenUnion = Union Identity
- openUnion :: forall a as. UElem a as (RIndex a as) => Prism' (OpenUnion as) a
Documentation
data Union (f :: u -> *) (as :: [u]) where #
A union is parameterized by a universe u, an interpretation f
and a list of labels as. The labels of the union are given by
inhabitants of the kind u; the type of values at any label a ::
u is given by its interpretation f a :: *.
Instances
| (Eq (f a2), Eq (Union a1 f as)) => Eq (Union a1 f ((:) a1 a2 as)) # | |
| Eq (Union u f ([] u)) # | |
| (Ord (f a2), Ord (Union a1 f as)) => Ord (Union a1 f ((:) a1 a2 as)) # | |
| Ord (Union u f ([] u)) # | |
| (Show (f a2), Show (Union a1 f as)) => Show (Union a1 f ((:) a1 a2 as)) # | |
| Show (Union u f ([] u)) # | |
| ((~) (* -> *) f Identity, Exception a, Typeable [*] as, Exception (Union * f as)) => Exception (Union * f ((:) * a as)) # | |
| (~) (* -> *) f Identity => Exception (Union * f ([] *)) # | |
| (NFData (f a2), NFData (Union a1 f as)) => NFData (Union a1 f ((:) a1 a2 as)) # | |
| NFData (Union u f ([] u)) # | |
absurdUnion :: Union f '[] -> a #
Since a union with an empty list of labels is uninhabited, we can recover any type from it.
class i ~ RIndex a as => UElem (a :: u) (as :: [u]) (i :: Nat) where #