hakaru-0.3.0: A probabilistic programming language

CopyrightCopyright (c) 2016 the Hakaru team
LicenseBSD3
Maintainerwren@community.haskell.org
Stabilityexperimental
PortabilityGHC-only
Safe HaskellNone
LanguageHaskell2010

Language.Hakaru.Syntax.Datum

Contents

Description

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 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.

Constructors

Datum :: !Text -> !(Sing (HData' t)) -> !(DatumCode (Code t) ast (HData' t)) -> Datum ast (HData' t) 

Instances

Traversable11 Hakaru Hakaru Datum Source # 

Methods

traverse11 :: Applicative f => (forall i. a i -> f (b i)) -> t a j -> f (t b j) Source #

Foldable11 Hakaru Hakaru Datum Source # 

Methods

fold11 :: Monoid m => f (Lift1 k1 m) i -> m Source #

foldMap11 :: Monoid m => (forall i. a i -> m) -> f a j -> m Source #

Functor11 Hakaru Hakaru Datum Source # 

Methods

fmap11 :: (forall i. a i -> b i) -> f a j -> f b j Source #

Eq1 Hakaru ast => JmEq1 Hakaru (Datum ast) Source # 

Methods

jmEq1 :: a i -> a j -> Maybe (TypeEq (Datum ast) i j) Source #

Eq1 Hakaru ast => Eq1 Hakaru (Datum ast) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru ast => Show1 Hakaru (Datum ast) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Pretty f => Pretty (Datum f) Source # 

Methods

prettyPrec_ :: Int -> Datum f a -> Docs Source #

Eq1 Hakaru ast => Eq (Datum ast a) Source # 

Methods

(==) :: Datum ast a -> Datum ast a -> Bool #

(/=) :: Datum ast a -> Datum ast a -> Bool #

Show1 Hakaru ast => Show (Datum ast a) Source # 

Methods

showsPrec :: Int -> Datum ast a -> ShowS #

show :: Datum ast a -> String #

showList :: [Datum ast a] -> ShowS #

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.

Constructors

Inr :: !(DatumCode xss abt a) -> DatumCode (xs ': xss) abt a 
Inl :: !(DatumStruct xs abt a) -> DatumCode (xs ': xss) abt a 

Instances

Traversable11 Hakaru Hakaru (DatumCode xss) Source # 

Methods

traverse11 :: Applicative f => (forall i. a i -> f (b i)) -> t a j -> f (t b j) Source #

Foldable11 Hakaru Hakaru (DatumCode xss) Source # 

Methods

fold11 :: Monoid m => f (Lift1 k1 m) i -> m Source #

foldMap11 :: Monoid m => (forall i. a i -> m) -> f a j -> m Source #

Functor11 Hakaru Hakaru (DatumCode xss) Source # 

Methods

fmap11 :: (forall i. a i -> b i) -> f a j -> f b j Source #

Eq1 Hakaru ast => Eq1 Hakaru (DatumCode xss ast) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru ast => Show1 Hakaru (DatumCode xss ast) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq1 Hakaru ast => Eq (DatumCode xss ast a) Source # 

Methods

(==) :: DatumCode xss ast a -> DatumCode xss ast a -> Bool #

(/=) :: DatumCode xss ast a -> DatumCode xss ast a -> Bool #

Show1 Hakaru ast => Show (DatumCode xss ast a) Source # 

Methods

showsPrec :: Int -> DatumCode xss ast a -> ShowS #

show :: DatumCode xss ast a -> String #

showList :: [DatumCode xss ast a] -> ShowS #

data DatumStruct :: [HakaruFun] -> (Hakaru -> *) -> Hakaru -> * where Source #

Constructors

Et :: !(DatumFun x abt a) -> !(DatumStruct xs abt a) -> DatumStruct (x ': xs) abt a infixr 7 
Done :: DatumStruct '[] abt a 

Instances

Traversable11 Hakaru Hakaru (DatumStruct xs) Source # 

Methods

traverse11 :: Applicative f => (forall i. a i -> f (b i)) -> t a j -> f (t b j) Source #

Foldable11 Hakaru Hakaru (DatumStruct xs) Source # 

Methods

fold11 :: Monoid m => f (Lift1 k1 m) i -> m Source #

foldMap11 :: Monoid m => (forall i. a i -> m) -> f a j -> m Source #

Functor11 Hakaru Hakaru (DatumStruct xs) Source # 

Methods

fmap11 :: (forall i. a i -> b i) -> f a j -> f b j Source #

Eq1 Hakaru ast => Eq1 Hakaru (DatumStruct xs ast) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru ast => Show1 Hakaru (DatumStruct xs ast) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq1 Hakaru ast => Eq (DatumStruct xs ast a) Source # 

Methods

(==) :: DatumStruct xs ast a -> DatumStruct xs ast a -> Bool #

(/=) :: DatumStruct xs ast a -> DatumStruct xs ast a -> Bool #

Show1 Hakaru ast => Show (DatumStruct xs ast a) Source # 

Methods

showsPrec :: Int -> DatumStruct xs ast a -> ShowS #

show :: DatumStruct xs ast a -> String #

showList :: [DatumStruct xs ast a] -> ShowS #

data DatumFun :: HakaruFun -> (Hakaru -> *) -> Hakaru -> * where Source #

Constructors

Konst :: !(ast b) -> DatumFun (K b) ast a 
Ident :: !(ast a) -> DatumFun I ast a 

Instances

Traversable11 Hakaru Hakaru (DatumFun x) Source # 

Methods

traverse11 :: Applicative f => (forall i. a i -> f (b i)) -> t a j -> f (t b j) Source #

Foldable11 Hakaru Hakaru (DatumFun x) Source # 

Methods

fold11 :: Monoid m => f (Lift1 k1 m) i -> m Source #

foldMap11 :: Monoid m => (forall i. a i -> m) -> f a j -> m Source #

Functor11 Hakaru Hakaru (DatumFun x) Source # 

Methods

fmap11 :: (forall i. a i -> b i) -> f a j -> f b j Source #

Eq1 Hakaru ast => Eq1 Hakaru (DatumFun x ast) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru ast => Show1 Hakaru (DatumFun x ast) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq1 Hakaru ast => Eq (DatumFun x ast a) Source # 

Methods

(==) :: DatumFun x ast a -> DatumFun x ast a -> Bool #

(/=) :: DatumFun x ast a -> DatumFun x ast a -> Bool #

Show1 Hakaru ast => Show (DatumFun x ast a) Source # 

Methods

showsPrec :: Int -> DatumFun x ast a -> ShowS #

show :: DatumFun x ast a -> String #

showList :: [DatumFun x ast a] -> ShowS #

Some smart constructors for the "built-in" datatypes

dPair :: (SingI a, SingI b) => ast a -> ast b -> Datum ast (HPair a b) Source #

dLeft :: (SingI a, SingI b) => ast a -> Datum ast (HEither a b) Source #

dRight :: (SingI a, SingI b) => ast b -> Datum ast (HEither a b) Source #

dNil :: SingI a => Datum ast (HList a) Source #

dCons :: SingI a => ast a -> ast (HList a) -> Datum ast (HList a) Source #

dNothing :: SingI a => Datum ast (HMaybe a) Source #

dJust :: SingI a => ast a -> Datum ast (HMaybe a) Source #

Variants which allow explicit type passing.

dPair_ :: Sing a -> Sing b -> ast a -> ast b -> Datum ast (HPair a b) Source #

dLeft_ :: Sing a -> Sing b -> ast a -> Datum ast (HEither a b) Source #

dRight_ :: Sing a -> Sing b -> ast b -> Datum ast (HEither a b) Source #

dNil_ :: Sing a -> Datum ast (HList a) Source #

dCons_ :: Sing a -> ast a -> ast (HList a) -> Datum ast (HList a) Source #

dNothing_ :: Sing a -> Datum ast (HMaybe a) Source #

dJust_ :: Sing a -> ast a -> Datum ast (HMaybe a) Source #

Pattern constructors

data Branch a abt b Source #

Constructors

Branch !(Pattern xs a) !(abt xs b) 

Instances

Traversable21 Hakaru Hakaru [Hakaru] (Branch a) Source # 

Methods

traverse21 :: Applicative f => (forall h i. a h i -> f (b h i)) -> t a j -> f (t b j) Source #

Foldable21 Hakaru Hakaru [Hakaru] (Branch a) Source # 

Methods

fold21 :: Monoid m => f (Lift2 k2 k1 m) j -> m Source #

foldMap21 :: Monoid m => (forall h i. a h i -> m) -> f a j -> m Source #

Functor21 Hakaru Hakaru [Hakaru] (Branch a) Source # 

Methods

fmap21 :: (forall h i. a h i -> b h i) -> f a j -> f b j Source #

Eq2 Hakaru [Hakaru] abt => Eq1 Hakaru (Branch a abt) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show2 Hakaru [Hakaru] abt => Show1 Hakaru (Branch a abt) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

ABT Hakaru Term abt => Pretty (Branch a abt) Source # 

Methods

prettyPrec_ :: Int -> Branch a abt a -> Docs Source #

Eq2 Hakaru [Hakaru] abt => Eq (Branch a abt b) Source # 

Methods

(==) :: Branch a abt b -> Branch a abt b -> Bool #

(/=) :: Branch a abt b -> Branch a abt b -> Bool #

Show2 Hakaru [Hakaru] abt => Show (Branch a abt b) Source # 

Methods

showsPrec :: Int -> Branch a abt b -> ShowS #

show :: Branch a abt b -> String #

showList :: [Branch a abt b] -> ShowS #

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.

Constructors

PWild :: Pattern '[] a 
PVar :: Pattern '[a] a 
PDatum :: !Text -> !(PDatumCode (Code t) vars (HData' t)) -> Pattern vars (HData' t) 

Instances

Eq1 Hakaru (Pattern vars) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru (Pattern vars) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq2 Hakaru [Hakaru] Pattern Source # 

Methods

eq2 :: a i j -> a i j -> Bool Source #

Show2 Hakaru [Hakaru] Pattern Source # 

Methods

showsPrec2 :: Int -> a i j -> ShowS Source #

show2 :: a i j -> String Source #

Pretty (Pattern xs) Source # 

Methods

prettyPrec_ :: Int -> Pattern xs a -> Docs Source #

Eq (Pattern vars a) Source # 

Methods

(==) :: Pattern vars a -> Pattern vars a -> Bool #

(/=) :: Pattern vars a -> Pattern vars a -> Bool #

Show (Pattern vars a) Source # 

Methods

showsPrec :: Int -> Pattern vars a -> ShowS #

show :: Pattern vars a -> String #

showList :: [Pattern vars a] -> ShowS #

data PDatumCode :: [[HakaruFun]] -> [Hakaru] -> Hakaru -> * where Source #

Constructors

PInr :: !(PDatumCode xss vars a) -> PDatumCode (xs ': xss) vars a 
PInl :: !(PDatumStruct xs vars a) -> PDatumCode (xs ': xss) vars a 

Instances

Eq2 Hakaru [Hakaru] (PDatumCode xss) Source # 

Methods

eq2 :: a i j -> a i j -> Bool Source #

Show2 Hakaru [Hakaru] (PDatumCode xss) Source # 

Methods

showsPrec2 :: Int -> a i j -> ShowS Source #

show2 :: a i j -> String Source #

Eq1 Hakaru (PDatumCode xss vars) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru (PDatumCode xss vars) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq (PDatumCode xss vars a) Source # 

Methods

(==) :: PDatumCode xss vars a -> PDatumCode xss vars a -> Bool #

(/=) :: PDatumCode xss vars a -> PDatumCode xss vars a -> Bool #

Show (PDatumCode xss vars a) Source # 

Methods

showsPrec :: Int -> PDatumCode xss vars a -> ShowS #

show :: PDatumCode xss vars a -> String #

showList :: [PDatumCode xss vars a] -> ShowS #

data PDatumStruct :: [HakaruFun] -> [Hakaru] -> Hakaru -> * where Source #

Constructors

PEt :: !(PDatumFun x vars1 a) -> !(PDatumStruct xs vars2 a) -> PDatumStruct (x ': xs) (vars1 ++ vars2) a infixr 7 
PDone :: PDatumStruct '[] '[] a 

Instances

Eq2 Hakaru [Hakaru] (PDatumStruct xs) Source # 

Methods

eq2 :: a i j -> a i j -> Bool Source #

Show2 Hakaru [Hakaru] (PDatumStruct xs) Source # 

Methods

showsPrec2 :: Int -> a i j -> ShowS Source #

show2 :: a i j -> String Source #

Eq1 Hakaru (PDatumStruct xs vars) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru (PDatumStruct xs vars) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq (PDatumStruct xs vars a) Source # 

Methods

(==) :: PDatumStruct xs vars a -> PDatumStruct xs vars a -> Bool #

(/=) :: PDatumStruct xs vars a -> PDatumStruct xs vars a -> Bool #

Show (PDatumStruct xs vars a) Source # 

Methods

showsPrec :: Int -> PDatumStruct xs vars a -> ShowS #

show :: PDatumStruct xs vars a -> String #

showList :: [PDatumStruct xs vars a] -> ShowS #

data PDatumFun :: HakaruFun -> [Hakaru] -> Hakaru -> * where Source #

Constructors

PKonst :: !(Pattern vars b) -> PDatumFun (K b) vars a 
PIdent :: !(Pattern vars a) -> PDatumFun I vars a 

Instances

Eq2 Hakaru [Hakaru] (PDatumFun x) Source # 

Methods

eq2 :: a i j -> a i j -> Bool Source #

Show2 Hakaru [Hakaru] (PDatumFun x) Source # 

Methods

showsPrec2 :: Int -> a i j -> ShowS Source #

show2 :: a i j -> String Source #

Eq1 Hakaru (PDatumFun x vars) Source # 

Methods

eq1 :: a i -> a i -> Bool Source #

Show1 Hakaru (PDatumFun x vars) Source # 

Methods

showsPrec1 :: Int -> a i -> ShowS Source #

show1 :: a i -> String Source #

Eq (PDatumFun x vars a) Source # 

Methods

(==) :: PDatumFun x vars a -> PDatumFun x vars a -> Bool #

(/=) :: PDatumFun x vars a -> PDatumFun x vars a -> Bool #

Show (PDatumFun x vars a) Source # 

Methods

showsPrec :: Int -> PDatumFun x vars a -> ShowS #

show :: PDatumFun x vars a -> String #

showList :: [PDatumFun x vars a] -> ShowS #

Some smart constructors for the "built-in" datatypes

pPair :: Pattern vars1 a -> Pattern vars2 b -> Pattern (vars1 ++ vars2) (HPair a b) Source #

pLeft :: Pattern vars a -> Pattern vars (HEither a b) Source #

pRight :: Pattern vars b -> Pattern vars (HEither a b) Source #

pCons :: Pattern vars1 a -> Pattern vars2 (HList a) -> Pattern (vars1 ++ vars2) (HList a) Source #

pJust :: Pattern vars a -> Pattern vars (HMaybe a) Source #

Generalized branches

data GBranch a r Source #

A generalization of the Branch type to allow a "body" of any Haskell type.

Constructors

GBranch !(Pattern xs a) !(List1 Variable xs) r 

Instances

Functor (GBranch a) Source # 

Methods

fmap :: (a -> b) -> GBranch a a -> GBranch a b #

(<$) :: a -> GBranch a b -> GBranch a a #

Foldable (GBranch a) Source # 

Methods

fold :: Monoid m => GBranch a m -> m #

foldMap :: Monoid m => (a -> m) -> GBranch a a -> m #

foldr :: (a -> b -> b) -> b -> GBranch a a -> b #

foldr' :: (a -> b -> b) -> b -> GBranch a a -> b #

foldl :: (b -> a -> b) -> b -> GBranch a a -> b #

foldl' :: (b -> a -> b) -> b -> GBranch a a -> b #

foldr1 :: (a -> a -> a) -> GBranch a a -> a #

foldl1 :: (a -> a -> a) -> GBranch a a -> a #

toList :: GBranch a a -> [a] #

null :: GBranch a a -> Bool #

length :: GBranch a a -> Int #

elem :: Eq a => a -> GBranch a a -> Bool #

maximum :: Ord a => GBranch a a -> a #

minimum :: Ord a => GBranch a a -> a #

sum :: Num a => GBranch a a -> a #

product :: Num a => GBranch a a -> a #

Traversable (GBranch a) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> GBranch a a -> f (GBranch a b) #

sequenceA :: Applicative f => GBranch a (f a) -> f (GBranch a a) #

mapM :: Monad m => (a -> m b) -> GBranch a a -> m (GBranch a b) #

sequence :: Monad m => GBranch a (m a) -> m (GBranch a a) #