Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
Haskell types and helpers for Hakaru's user-defined data types. At present we only support regular-recursive polynomial data types. Reduction of case analysis on data types is in Language.Hakaru.Syntax.Datum.
Developers note: many of the JmEq1
instances in this file
don't actually work because of problems with matching existentially
quantified types in the basis cases. For now I've left the
partially-defined code in place, but turned it off with the
PARTIAL_DATUM_JMEQ
CPP macro. In the future we should
either (a) remove this unused code, or (b) if the instances are
truly necessary then we should add the Sing
arguments everywhere
to make things work :(
Synopsis
- data Datum :: (Hakaru -> *) -> Hakaru -> * where
- datumHint :: Datum ast (HData' t) -> Text
- datumType :: Datum ast (HData' t) -> Sing (HData' t)
- data DatumCode :: [[HakaruFun]] -> (Hakaru -> *) -> Hakaru -> * where
- data DatumStruct :: [HakaruFun] -> (Hakaru -> *) -> Hakaru -> * where
- Et :: !(DatumFun x abt a) -> !(DatumStruct xs abt a) -> DatumStruct (x ': xs) abt a
- Done :: DatumStruct '[] abt a
- data DatumFun :: HakaruFun -> (Hakaru -> *) -> Hakaru -> * where
- dTrue :: Datum ast HBool
- dFalse :: Datum ast HBool
- dBool :: Bool -> Datum ast HBool
- dUnit :: Datum ast HUnit
- dPair :: (SingI a, SingI b) => ast a -> ast b -> Datum ast (HPair a b)
- dLeft :: (SingI a, SingI b) => ast a -> Datum ast (HEither a b)
- dRight :: (SingI a, SingI b) => ast b -> Datum ast (HEither a b)
- dNil :: SingI a => Datum ast (HList a)
- dCons :: SingI a => ast a -> ast (HList a) -> Datum ast (HList a)
- dNothing :: SingI a => Datum ast (HMaybe a)
- dJust :: SingI a => ast a -> Datum ast (HMaybe a)
- dPair_ :: Sing a -> Sing b -> ast a -> ast b -> Datum ast (HPair a b)
- dLeft_ :: Sing a -> Sing b -> ast a -> Datum ast (HEither a b)
- dRight_ :: Sing a -> Sing b -> ast b -> Datum ast (HEither a b)
- dNil_ :: Sing a -> Datum ast (HList a)
- dCons_ :: Sing a -> ast a -> ast (HList a) -> Datum ast (HList a)
- dNothing_ :: Sing a -> Datum ast (HMaybe a)
- dJust_ :: Sing a -> ast a -> Datum ast (HMaybe a)
- data Branch (a :: Hakaru) (abt :: [Hakaru] -> Hakaru -> *) (b :: Hakaru) = forall xs. Branch !(Pattern xs a) !(abt xs b)
- data Pattern :: [Hakaru] -> Hakaru -> * where
- data PDatumCode :: [[HakaruFun]] -> [Hakaru] -> Hakaru -> * where
- PInr :: !(PDatumCode xss vars a) -> PDatumCode (xs ': xss) vars a
- PInl :: !(PDatumStruct xs vars a) -> PDatumCode (xs ': xss) vars a
- data PDatumStruct :: [HakaruFun] -> [Hakaru] -> Hakaru -> * where
- PEt :: !(PDatumFun x vars1 a) -> !(PDatumStruct xs vars2 a) -> PDatumStruct (x ': xs) (vars1 ++ vars2) a
- PDone :: PDatumStruct '[] '[] a
- data PDatumFun :: HakaruFun -> [Hakaru] -> Hakaru -> * where
- pTrue :: Pattern '[] HBool
- pFalse :: Pattern '[] HBool
- pUnit :: Pattern '[] HUnit
- pPair :: Pattern vars1 a -> Pattern vars2 b -> Pattern (vars1 ++ vars2) (HPair a b)
- pLeft :: Pattern vars a -> Pattern vars (HEither a b)
- pRight :: Pattern vars b -> Pattern vars (HEither a b)
- pNil :: Pattern '[] (HList a)
- pCons :: Pattern vars1 a -> Pattern vars2 (HList a) -> Pattern (vars1 ++ vars2) (HList a)
- pNothing :: Pattern '[] (HMaybe a)
- pJust :: Pattern vars a -> Pattern vars (HMaybe a)
- data GBranch (a :: Hakaru) (r :: *) = forall xs. GBranch !(Pattern xs a) !(List1 Variable xs) r
Data constructors
data Datum :: (Hakaru -> *) -> Hakaru -> * where Source #
A fully saturated data constructor, which recurses as ast
.
We define this type as separate from DatumCode
for two reasons.
First is to capture the fact that the datum is "complete"
(i.e., is a well-formed constructor). The second is to have a
type which is indexed by its Hakaru
type, whereas DatumCode
involves non-Hakaru types.
The first component is a hint for what the data constructor should be called when pretty-printing, giving error messages, etc. Like the hints for variable names, its value is not actually used to decide which constructor is meant or which pattern matches.
Datum :: !Text -> !(Sing (HData' t)) -> !(DatumCode (Code t) ast (HData' t)) -> Datum ast (HData' t) |
Instances
Traversable11 Datum Source # | |
Defined in Language.Hakaru.Syntax.Datum traverse11 :: forall f a b (j :: k2). Applicative f => (forall (i :: k1). a i -> f (b i)) -> Datum a j -> f (Datum b j) Source # | |
Foldable11 Datum Source # | |
Functor11 Datum Source # | |
Eq1 ast => JmEq1 (Datum ast :: Hakaru -> Type) Source # | |
Eq1 ast => Eq1 (Datum ast :: Hakaru -> Type) Source # | |
Show1 ast => Show1 (Datum ast :: Hakaru -> Type) Source # | |
Pretty f => Pretty (Datum f) Source # | |
Defined in Language.Hakaru.Pretty.Haskell | |
Eq1 ast => Eq (Datum ast a) Source # | |
Show1 ast => Show (Datum ast a) Source # | |
data DatumCode :: [[HakaruFun]] -> (Hakaru -> *) -> Hakaru -> * where Source #
The intermediate components of a data constructor. The intuition
behind the two indices is that the [[HakaruFun]]
is a functor
applied to the Hakaru type. Initially the [[HakaruFun]]
functor
will be the Code
associated with the Hakaru type; hence it's
the one-step unrolling of the fixed point for our recursive
datatypes. But as we go along, we'll be doing induction on the
[[HakaruFun]]
functor.
Inr :: !(DatumCode xss abt a) -> DatumCode (xs ': xss) abt a | |
Inl :: !(DatumStruct xs abt a) -> DatumCode (xs ': xss) abt a |
Instances
Traversable11 (DatumCode xss :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Defined in Language.Hakaru.Syntax.Datum traverse11 :: forall f a b (j :: k2). Applicative f => (forall (i :: k1). a i -> f (b i)) -> DatumCode xss a j -> f (DatumCode xss b j) Source # | |
Foldable11 (DatumCode xss :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Functor11 (DatumCode xss :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Eq1 ast => Eq1 (DatumCode xss ast :: Hakaru -> Type) Source # | |
Show1 ast => Show1 (DatumCode xss ast :: Hakaru -> Type) Source # | |
Eq1 ast => Eq (DatumCode xss ast a) Source # | |
Show1 ast => Show (DatumCode xss ast a) Source # | |
data DatumStruct :: [HakaruFun] -> (Hakaru -> *) -> Hakaru -> * where Source #
Et :: !(DatumFun x abt a) -> !(DatumStruct xs abt a) -> DatumStruct (x ': xs) abt a infixr 7 | |
Done :: DatumStruct '[] abt a |
Instances
data DatumFun :: HakaruFun -> (Hakaru -> *) -> Hakaru -> * where Source #
Instances
Traversable11 (DatumFun x :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Defined in Language.Hakaru.Syntax.Datum traverse11 :: forall f a b (j :: k2). Applicative f => (forall (i :: k1). a i -> f (b i)) -> DatumFun x a j -> f (DatumFun x b j) Source # | |
Foldable11 (DatumFun x :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Functor11 (DatumFun x :: (Hakaru -> Type) -> Hakaru -> Type) Source # | |
Eq1 ast => Eq1 (DatumFun x ast :: Hakaru -> Type) Source # | |
Show1 ast => Show1 (DatumFun x ast :: Hakaru -> Type) Source # | |
Eq1 ast => Eq (DatumFun x ast a) Source # | |
Show1 ast => Show (DatumFun x ast a) Source # | |
Some smart constructors for the "built-in" datatypes
Variants which allow explicit type passing.
Pattern constructors
data Branch (a :: Hakaru) (abt :: [Hakaru] -> Hakaru -> *) (b :: Hakaru) Source #
Instances
Eq2 abt => Eq1 (Branch a abt :: Hakaru -> Type) Source # | |
Show2 abt => Show1 (Branch a abt :: Hakaru -> Type) Source # | |
Traversable21 (Branch a :: ([Hakaru] -> Hakaru -> Type) -> Hakaru -> Type) Source # | |
Defined in Language.Hakaru.Syntax.Datum traverse21 :: forall f a0 b (j :: k3). Applicative f => (forall (h :: k1) (i :: k2). a0 h i -> f (b h i)) -> Branch a a0 j -> f (Branch a b j) Source # | |
Foldable21 (Branch a :: ([Hakaru] -> Hakaru -> Type) -> Hakaru -> Type) Source # | |
Functor21 (Branch a :: ([Hakaru] -> Hakaru -> Type) -> Hakaru -> Type) Source # | |
ABT Term abt => Coerce (Branch a abt) Source # | |
ABT Term abt => Pretty (Branch a abt) Source # | |
Defined in Language.Hakaru.Pretty.Haskell | |
Eq2 abt => Eq (Branch a abt b) Source # | |
Show2 abt => Show (Branch a abt b) Source # | |
data Pattern :: [Hakaru] -> Hakaru -> * where Source #
We index patterns by the type they scrutinize. This requires
the parser to be smart enough to build these patterns up, but
then it guarantees that we can't have Case_
of patterns which
can't possibly match according to our type system. In addition,
we also index patterns by the type of what variables they bind,
so that we can ensure that Branch
will never "go wrong".
Alas, this latter indexing means we can't use DatumCode
,
DatumStruct
, and DatumFun
but rather must define our own P
variants for pattern matching.
PWild :: Pattern '[] a | |
PVar :: Pattern '[a] a | |
PDatum :: !Text -> !(PDatumCode (Code t) vars (HData' t)) -> Pattern vars (HData' t) |
data PDatumCode :: [[HakaruFun]] -> [Hakaru] -> Hakaru -> * where Source #
PInr :: !(PDatumCode xss vars a) -> PDatumCode (xs ': xss) vars a | |
PInl :: !(PDatumStruct xs vars a) -> PDatumCode (xs ': xss) vars a |
Instances
data PDatumStruct :: [HakaruFun] -> [Hakaru] -> Hakaru -> * where Source #
PEt :: !(PDatumFun x vars1 a) -> !(PDatumStruct xs vars2 a) -> PDatumStruct (x ': xs) (vars1 ++ vars2) a infixr 7 | |
PDone :: PDatumStruct '[] '[] a |
Instances
data PDatumFun :: HakaruFun -> [Hakaru] -> Hakaru -> * where Source #
PKonst :: !(Pattern vars b) -> PDatumFun ('K b) vars a | |
PIdent :: !(Pattern vars a) -> PDatumFun 'I vars a |
Some smart constructors for the "built-in" datatypes
Generalized branches
data GBranch (a :: Hakaru) (r :: *) Source #
A generalization of the Branch
type to allow a "body" of
any Haskell type.
Instances
Functor (GBranch a) Source # | |
Foldable (GBranch a) Source # | |
Defined in Language.Hakaru.Syntax.Datum fold :: Monoid m => GBranch a m -> m # foldMap :: Monoid m => (a0 -> m) -> GBranch a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> GBranch a a0 -> m # foldr :: (a0 -> b -> b) -> b -> GBranch a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> GBranch a a0 -> b # foldl :: (b -> a0 -> b) -> b -> GBranch a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> GBranch a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> GBranch a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> GBranch a a0 -> a0 # toList :: GBranch a a0 -> [a0] # null :: GBranch a a0 -> Bool # length :: GBranch a a0 -> Int # elem :: Eq a0 => a0 -> GBranch a a0 -> Bool # maximum :: Ord a0 => GBranch a a0 -> a0 # minimum :: Ord a0 => GBranch a a0 -> a0 # | |
Traversable (GBranch a) Source # | |
Defined in Language.Hakaru.Syntax.Datum |