-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Extensible type-safe unions -- -- Extensible type-safe unions for Haskell with prisms using modern GHC -- features. Dual to vinyl records. Unions are also known as corecords or -- polymorphic variants. Neither requires a Typeable constraint -- nor uses unsafe coercions at the cost of linear time access -- (negligible in practice). @package union @version 0.1.2 -- | Extensible type-safe unions. -- --
-- >>> let a = openUnion # (5 :: Int) :: OpenUnion '[Bool, Int] ---- --
-- >>> a ^? openUnion @Int -- Just 5 ---- --
-- >>> a ^? openUnion @Bool -- Nothing ---- --
-- >>> a ^? openUnion @Char -- <interactive>:7:6: error: -- • No instance for (UElem Char '[] (RIndex Char '[])) -- arising from a use of ‘openUnion’ -- • In the second argument of ‘(^?)’, namely ‘openUnion @Char’ -- In the expression: a ^? openUnion @Char -- In an equation for ‘it’: it = a ^? openUnion @Char --module Data.Union -- | 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 :: -- *. data Union (f :: u -> *) (as :: [u]) [This] :: !(f a) -> Union f (a : as) [That] :: !(Union f as) -> Union f (a : as) -- | Case analysis for unions. union :: (Union f as -> c) -> (f a -> c) -> Union f (a : as) -> c -- | Since a union with an empty list of labels is uninhabited, we can -- recover any type from it. 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) uprism :: UElem a as i => Prism' (Union f as) (f a) ulift :: UElem a as i => f a -> Union f as umatch :: UElem a as i => Union f as -> Maybe (f a) class is ~ RImage as bs => USubset (as :: [u]) (bs :: [u]) is usubset :: USubset as bs is => Prism' (Union f bs) (Union f as) urelax :: USubset as bs is => Union f as -> Union f bs urestrict :: USubset as bs is => Union f bs -> Maybe (Union f as) type OpenUnion = Union Identity openUnion :: forall a as. UElem a as (RIndex a as) => Prism' (OpenUnion as) a instance forall u (bs :: [u]). Data.Union.USubset '[] bs '[] instance forall u (a :: u) (bs :: [u]) (i :: Data.Vinyl.TypeLevel.Nat) (as :: [u]) (is :: [Data.Vinyl.TypeLevel.Nat]). (Data.Union.UElem a bs i, Data.Union.USubset as bs is) => Data.Union.USubset (a : as) bs (i : is) instance forall a1 (a2 :: a1) (as :: [a1]). Data.Union.UElem a2 (a2 : as) 'Data.Vinyl.TypeLevel.Z instance forall a1 (a2 :: a1) (b :: a1) (as :: [a1]) (i :: Data.Vinyl.TypeLevel.Nat). (Data.Vinyl.TypeLevel.RIndex a2 (b : as) ~ 'Data.Vinyl.TypeLevel.S i, Data.Union.UElem a2 as i) => Data.Union.UElem a2 (b : as) ('Data.Vinyl.TypeLevel.S i) instance forall u (f :: u -> *). Control.DeepSeq.NFData (Data.Union.Union f '[]) instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (Control.DeepSeq.NFData (f a2), Control.DeepSeq.NFData (Data.Union.Union f as)) => Control.DeepSeq.NFData (Data.Union.Union f (a2 : as)) instance forall u (f :: u -> *). GHC.Show.Show (Data.Union.Union f '[]) instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Show.Show (f a2), GHC.Show.Show (Data.Union.Union f as)) => GHC.Show.Show (Data.Union.Union f (a2 : as)) instance forall u (f :: u -> *). GHC.Classes.Eq (Data.Union.Union f '[]) instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Classes.Eq (f a2), GHC.Classes.Eq (Data.Union.Union f as)) => GHC.Classes.Eq (Data.Union.Union f (a2 : as)) instance forall u (f :: u -> *). GHC.Classes.Ord (Data.Union.Union f '[]) instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (GHC.Classes.Ord (f a2), GHC.Classes.Ord (Data.Union.Union f as)) => GHC.Classes.Ord (Data.Union.Union f (a2 : as)) instance (f ~ Data.Functor.Identity.Identity) => GHC.Exception.Exception (Data.Union.Union f '[]) instance (f ~ Data.Functor.Identity.Identity, GHC.Exception.Exception a, Data.Typeable.Internal.Typeable as, GHC.Exception.Exception (Data.Union.Union f as)) => GHC.Exception.Exception (Data.Union.Union f (a : as)) instance forall u (f :: u -> *). GHC.Generics.Generic (Data.Union.Union f '[]) instance forall u (f :: u -> *) (a :: u) (as :: [u]). GHC.Generics.Generic (Data.Union.Union f (a : as)) instance forall u (f :: u -> *). Data.Hashable.Class.Hashable (Data.Union.Union f '[]) instance forall a1 (f :: a1 -> *) (a2 :: a1) (as :: [a1]). (Data.Hashable.Class.Hashable (f a2), Data.Hashable.Class.Hashable (Data.Union.Union f as)) => Data.Hashable.Class.Hashable (Data.Union.Union f (a2 : as))