variant-1.0.2: Variant and EADT
Safe HaskellNone
LanguageHaskell2010

Data.Variant.EGADT

Synopsis

Documentation

>>> :seti -XDataKinds
>>> :seti -XTypeApplications
>>> :seti -XTypeOperators
>>> :seti -XFlexibleContexts
>>> :seti -XTypeFamilies
>>> :seti -XPatternSynonyms
>>> :seti -XDeriveFunctor
>>> :seti -XGADTs
>>> :seti -XPolyKinds
>>> :seti -XPartialTypeSignatures
>>> 
>>> :{
>>> data LamF (ast :: Type -> Type) t where
>>> LamF :: ( ast a -> ast b ) -> LamF ast ( a -> b )
>>> 
>>> data AppF ast t where
>>> AppF :: ast ( a -> b ) -> ast a -> AppF ast b
>>> 
>>> data VarF ast t where
>>> VarF :: String -> VarF ast Int
>>> 
>>> type AST a = EGADT '[LamF,AppF,VarF] a
>>> 
>>> :}
>>> let y = VF @(AST Int) (VarF "a")
>>> :t y
y :: EGADT [LamF, AppF, VarF] Int
>>> :{
>>> case y of
>>> VF (VarF x) -> print x
>>> _           -> putStrLn "Not a VarF"
>>> :}
"a"
>>> :{
>>> f :: AST Int -> AST Int
>>> f (VF (VarF x)) = VF (VarF "zz")
>>> f _             = error "Unhandled case"
>>> :}
>>> let z = VF (AppF (VF (LamF f)) (VF (VarF "a")))
>>> :t z
z :: EGADT [LamF, AppF, VarF] Int

newtype EGADT (fs :: [(k -> Type) -> k -> Type]) (t :: k) Source #

An EADT with an additional type parameter

Constructors

EGADT (HVariantF fs (EGADT fs) t) 

Instances

Instances details
HFunctor (HVariantF xs) => HCorecursive (EGADT xs :: k -> Type) Source # 
Instance details

Defined in Data.Variant.EGADT

Methods

hembed :: HAlgebra (HBase (EGADT xs)) (EGADT xs) Source #

hana :: forall (f :: k -> Type). HCoalgebra (HBase (EGADT xs)) f -> f ~> EGADT xs Source #

HFunctor (HVariantF xs) => HRecursive (EGADT xs :: k -> Type) Source # 
Instance details

Defined in Data.Variant.EGADT

Methods

hproject :: HCoalgebra (HBase (EGADT xs)) (EGADT xs) Source #

hcata :: forall (f :: k -> Type). HAlgebra (HBase (EGADT xs)) f -> EGADT xs ~> f Source #

type HBase (EGADT xs :: k -> Type) Source # 
Instance details

Defined in Data.Variant.EGADT

type HBase (EGADT xs :: k -> Type) = HVariantF xs

newtype HVariantF (fs :: [(k -> Type) -> k -> Type]) (ast :: k -> Type) (t :: k) Source #

Constructors

HVariantF (VariantF (ApplyAll ast fs) t) 

toHVariantAt :: forall {t1} {t2} (i :: Nat) (fs :: [t1 -> t2 -> Type]) (ast :: t1) (a :: t2). KnownNat i => Index i fs ast a -> VariantF (ApplyAll ast fs) a Source #

fromHVariantAt :: forall {t1} {t2} (i :: Nat) (fs :: [t1 -> t2 -> Type]) (ast :: t1) (a :: t2). KnownNat i => VariantF (ApplyAll ast fs) a -> Maybe (Index i fs ast a) Source #

type family (f :: k) :<! (fs :: [k]) where ... Source #

Equations

(f :: k) :<! (fs :: [k]) = MemberAtIndex (IndexOf f fs) f fs 

type family MemberAtIndex (i :: Nat) (f :: k) (fs :: [k]) where ... Source #

Equations

MemberAtIndex i (f :: k) (fs :: [k]) = (KnownNat i, Index i fs ~ f) 

type family (xs :: [k]) :<<! (ys :: [k]) where ... Source #

Equations

('[] :: [k]) :<<! (ys :: [k]) = () 
(x ': xs :: [k]) :<<! (ys :: [k]) = (x :<! ys, xs :<<! ys) 

pattern VF :: forall {k} e a f fs. (e ~ EGADT fs a, f :<! fs) => f (EGADT fs) a -> EGADT fs a Source #

Pattern-match in an extensible GADT