| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Variant.EGADT
Synopsis
- newtype EGADT fs t = EGADT (HVariantF fs (EGADT fs) t)
- newtype HVariantF (fs :: [(k -> Type) -> k -> Type]) (ast :: k -> Type) (t :: k) = HVariantF (VariantF (ApplyAll ast fs) t)
- toHVariantAt :: forall i fs ast a. KnownNat i => Index i fs ast a -> VariantF (ApplyAll ast fs) a
- fromHVariantAt :: forall i fs ast a. KnownNat i => VariantF (ApplyAll ast fs) a -> Maybe (Index i fs ast a)
- type family f :<! fs :: Constraint where ...
- type family MemberAtIndex (i :: Nat) f fs :: Constraint where ...
- type family xs :<<! ys :: Constraint where ...
- pattern VF :: forall e a f fs. (e ~ EGADT fs a, f :<! fs) => f (EGADT fs) a -> EGADT fs a
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 yy :: 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 zz :: EGADT [LamF, AppF, VarF] Int
An EADT with an additional type parameter
toHVariantAt :: forall i fs ast a. KnownNat i => Index i fs ast a -> VariantF (ApplyAll ast fs) a Source #
fromHVariantAt :: forall i fs ast a. KnownNat i => VariantF (ApplyAll ast fs) a -> Maybe (Index i fs ast a) Source #
type family f :<! fs :: Constraint where ... Source #
Equations
| f :<! fs = MemberAtIndex (IndexOf f fs) f fs |
type family MemberAtIndex (i :: Nat) f fs :: Constraint where ... Source #
Equations
| MemberAtIndex i f fs = (KnownNat i, Index i fs ~ f) |
type family xs :<<! ys :: Constraint where ... Source #