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 :(
- 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
- 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 abt b = 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 r = 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) |
Traversable11 Hakaru Hakaru Datum Source # | |
Foldable11 Hakaru Hakaru Datum Source # | |
Functor11 Hakaru Hakaru Datum Source # | |
Eq1 Hakaru ast => JmEq1 Hakaru (Datum ast) Source # | |
Eq1 Hakaru ast => Eq1 Hakaru (Datum ast) Source # | |
Show1 Hakaru ast => Show1 Hakaru (Datum ast) Source # | |
Pretty f => Pretty (Datum f) Source # | |
Eq1 Hakaru ast => Eq (Datum ast a) Source # | |
Show1 Hakaru 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 |
Traversable11 Hakaru Hakaru (DatumCode xss) Source # | |
Foldable11 Hakaru Hakaru (DatumCode xss) Source # | |
Functor11 Hakaru Hakaru (DatumCode xss) Source # | |
Eq1 Hakaru ast => Eq1 Hakaru (DatumCode xss ast) Source # | |
Show1 Hakaru ast => Show1 Hakaru (DatumCode xss ast) Source # | |
Eq1 Hakaru ast => Eq (DatumCode xss ast a) Source # | |
Show1 Hakaru 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 |
Traversable11 Hakaru Hakaru (DatumStruct xs) Source # | |
Foldable11 Hakaru Hakaru (DatumStruct xs) Source # | |
Functor11 Hakaru Hakaru (DatumStruct xs) Source # | |
Eq1 Hakaru ast => Eq1 Hakaru (DatumStruct xs ast) Source # | |
Show1 Hakaru ast => Show1 Hakaru (DatumStruct xs ast) Source # | |
Eq1 Hakaru ast => Eq (DatumStruct xs ast a) Source # | |
Show1 Hakaru ast => Show (DatumStruct xs ast a) Source # | |
data DatumFun :: HakaruFun -> (Hakaru -> *) -> Hakaru -> * where Source #
Traversable11 Hakaru Hakaru (DatumFun x) Source # | |
Foldable11 Hakaru Hakaru (DatumFun x) Source # | |
Functor11 Hakaru Hakaru (DatumFun x) Source # | |
Eq1 Hakaru ast => Eq1 Hakaru (DatumFun x ast) Source # | |
Show1 Hakaru ast => Show1 Hakaru (DatumFun x ast) Source # | |
Eq1 Hakaru ast => Eq (DatumFun x ast a) Source # | |
Show1 Hakaru ast => Show (DatumFun x ast a) Source # | |
Some smart constructors for the "built-in" datatypes
Variants which allow explicit type passing.
Pattern constructors
Traversable21 Hakaru Hakaru [Hakaru] (Branch a) Source # | |
Foldable21 Hakaru Hakaru [Hakaru] (Branch a) Source # | |
Functor21 Hakaru Hakaru [Hakaru] (Branch a) Source # | |
Eq2 Hakaru [Hakaru] abt => Eq1 Hakaru (Branch a abt) Source # | |
Show2 Hakaru [Hakaru] abt => Show1 Hakaru (Branch a abt) Source # | |
ABT Hakaru Term abt => Pretty (Branch a abt) Source # | |
Eq2 Hakaru [Hakaru] abt => Eq (Branch a abt b) Source # | |
Show2 Hakaru [Hakaru] 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.
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 |
Eq2 Hakaru [Hakaru] (PDatumCode xss) Source # | |
Show2 Hakaru [Hakaru] (PDatumCode xss) Source # | |
Eq1 Hakaru (PDatumCode xss vars) Source # | |
Show1 Hakaru (PDatumCode xss vars) Source # | |
Eq (PDatumCode xss vars a) Source # | |
Show (PDatumCode xss vars a) Source # | |
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 |
Eq2 Hakaru [Hakaru] (PDatumStruct xs) Source # | |
Show2 Hakaru [Hakaru] (PDatumStruct xs) Source # | |
Eq1 Hakaru (PDatumStruct xs vars) Source # | |
Show1 Hakaru (PDatumStruct xs vars) Source # | |
Eq (PDatumStruct xs vars a) Source # | |
Show (PDatumStruct xs vars a) Source # | |
data PDatumFun :: HakaruFun -> [Hakaru] -> Hakaru -> * where Source #