Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
The internal syntax of Hakaru transformations, which are functions on Hakaru terms which are neither primitive, nor expressible in terms of Hakaru primitives.
Synopsis
- data TransformImpl
- data Transform :: [([Hakaru], Hakaru)] -> Hakaru -> * where
- Expect :: Transform '[LC (HMeasure a), '('[a], HProb)] HProb
- Observe :: Transform '[LC (HMeasure a), LC a] (HMeasure a)
- MH :: Transform '[LC (a :-> HMeasure a), LC (HMeasure a)] (a :-> HMeasure (HPair a HProb))
- MCMC :: Transform '[LC (a :-> HMeasure a), LC (HMeasure a)] (a :-> HMeasure a)
- Disint :: TransformImpl -> Transform '[LC (HMeasure (HPair a b))] (a :-> HMeasure b)
- Summarize :: Transform '[LC a] a
- Simplify :: Transform '[LC a] a
- Reparam :: Transform '[LC a] a
- transformName :: Transform args a -> String
- allTransforms :: [Some2 Transform]
- typeOfTransform :: Transform as x -> SArgsSing as -> Sing x
- newtype TransformCtx = TransformCtx {
- nextFreeVar :: Nat
- class HasTransformCtx x where
- unionCtx :: TransformCtx -> TransformCtx -> TransformCtx
- minimalCtx :: TransformCtx
- newtype TransformTable abt m = TransformTable {
- lookupTransform :: forall as b. Transform as b -> Maybe (TransformCtx -> SArgs abt as -> m (Maybe (abt '[] b)))
- lookupTransform' :: Applicative m => TransformTable abt m -> Transform as b -> TransformCtx -> SArgs abt as -> m (Maybe (abt '[] b))
- simpleTable :: Applicative m => (forall as b. Transform as b -> Maybe (TransformCtx -> SArgs abt as -> Maybe (abt '[] b))) -> TransformTable abt m
- unionTable :: TransformTable abt m -> TransformTable abt m -> TransformTable abt m
- someTransformations :: [Some2 Transform] -> TransformTable abt m -> TransformTable abt m
Transformation internal syntax
data TransformImpl Source #
Some transformations have the same type and same
semantics, but are
implemented in multiple different ways. Such transformations are
distinguished in concrete syntax by differing keywords.
Instances
data Transform :: [([Hakaru], Hakaru)] -> Hakaru -> * where Source #
Transformations and their types. Like SCon
.
Expect :: Transform '[LC (HMeasure a), '('[a], HProb)] HProb | |
Observe :: Transform '[LC (HMeasure a), LC a] (HMeasure a) | |
MH :: Transform '[LC (a :-> HMeasure a), LC (HMeasure a)] (a :-> HMeasure (HPair a HProb)) | |
MCMC :: Transform '[LC (a :-> HMeasure a), LC (HMeasure a)] (a :-> HMeasure a) | |
Disint :: TransformImpl -> Transform '[LC (HMeasure (HPair a b))] (a :-> HMeasure b) | |
Summarize :: Transform '[LC a] a | |
Simplify :: Transform '[LC a] a | |
Reparam :: Transform '[LC a] a |
Some utilities
transformName :: Transform args a -> String Source #
The concrete syntax names of transformations.
allTransforms :: [Some2 Transform] Source #
All transformations.
Mapping of input type to output type for transforms
Transformation contexts
newtype TransformCtx Source #
The context in which a transformation is called. Currently this is simply the next free variable in the enclosing program, but it could one day be expanded to include more information, e.g., an association of variables to terms in the enclosing program.
Instances
Eq TransformCtx Source # | |
(==) :: TransformCtx -> TransformCtx -> Bool # (/=) :: TransformCtx -> TransformCtx -> Bool # | |
Ord TransformCtx Source # | |
compare :: TransformCtx -> TransformCtx -> Ordering # (<) :: TransformCtx -> TransformCtx -> Bool # (<=) :: TransformCtx -> TransformCtx -> Bool # (>) :: TransformCtx -> TransformCtx -> Bool # (>=) :: TransformCtx -> TransformCtx -> Bool # max :: TransformCtx -> TransformCtx -> TransformCtx # min :: TransformCtx -> TransformCtx -> TransformCtx # | |
Show TransformCtx Source # | |
showsPrec :: Int -> TransformCtx -> ShowS # show :: TransformCtx -> String # showList :: [TransformCtx] -> ShowS # | |
Semigroup TransformCtx Source # | |
(<>) :: TransformCtx -> TransformCtx -> TransformCtx # sconcat :: NonEmpty TransformCtx -> TransformCtx # stimes :: Integral b => b -> TransformCtx -> TransformCtx # | |
Monoid TransformCtx Source # | |
mempty :: TransformCtx # mappend :: TransformCtx -> TransformCtx -> TransformCtx # mconcat :: [TransformCtx] -> TransformCtx # |
class HasTransformCtx x where Source #
The class of types which have an associated context
ctxOf :: x -> TransformCtx Source #
Instances
ABT syn abt => HasTransformCtx (abt xs a) Source # | |
ctxOf :: abt xs a -> TransformCtx Source # | |
HasTransformCtx (Variable a) Source # | |
ctxOf :: Variable a -> TransformCtx Source # |
unionCtx :: TransformCtx -> TransformCtx -> TransformCtx Source #
The union of two contexts
minimalCtx :: TransformCtx Source #
The smallest possible context, i.e. a default context suitable for use when performing induction on terms which may contain transformations as subterms.
Transformation tables
newtype TransformTable abt m Source #
A functional lookup table which indicates how to expand
transformations. The function returns Nothing
when the transformation
shouldn't be expanded. When it returns Just k
, k
is passed an SArgs
and a TransformCtx
.
TransformTable | |
|
lookupTransform' :: Applicative m => TransformTable abt m -> Transform as b -> TransformCtx -> SArgs abt as -> m (Maybe (abt '[] b)) Source #
A variant of lookupTransform
which joins the two layers of Maybe
.
simpleTable :: Applicative m => (forall as b. Transform as b -> Maybe (TransformCtx -> SArgs abt as -> Maybe (abt '[] b))) -> TransformTable abt m Source #
Builds a simple
transformation table, i.e. one which doesn't make use of
the monadic context. Such a table is valid in every Applicative
context.
unionTable :: TransformTable abt m -> TransformTable abt m -> TransformTable abt m Source #
Take the left-biased union of two transformation tables
someTransformations :: [Some2 Transform] -> TransformTable abt m -> TransformTable abt m Source #
Intersect a transformation table with a list of transformations