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

Contents

Description

 

Synopsis

Documentation

The expectation-evaluation monad

List-based version

data ListContext abt p Source #

An ordered collection of statements representing the context surrounding the current focus of our program transformation. That is, since some transformations work from the bottom up, we need to keep track of the statements we passed along the way when reaching for the bottom.

The tail of the list takes scope over the head of the list. Thus, the back/end of the list is towards the top of the program, whereas the front of the list is towards the bottom.

This type was formerly called Heap (presumably due to the Statement type being called Binding) but that seems like a misnomer to me since this really has nothing to do with allocation. However, it is still like a heap inasmuch as it's a dependency graph and we may wish to change the topological sorting or remove "garbage" (subject to correctness criteria).

TODO: Figure out what to do with SWeight, SGuard, SStuff, etc, so that we can use an IntMap (Statement abt) in order to speed up the lookup times in select. (Assuming callers don't use unsafePush unsafely: we can recover the order things were inserted from their varID since we've freshened them all and therefore their IDs are monotonic in the insertion order.)

Constructors

ListContext 

Fields

type ExpectAns abt = ListContext abt ExpectP -> abt '[] HProb Source #

newtype Expect abt x Source #

Constructors

Expect 

Fields

Instances

ABT Hakaru Term abt => EvaluationMonad abt (Expect abt) ExpectP Source # 
Monad (Expect abt) Source # 

Methods

(>>=) :: Expect abt a -> (a -> Expect abt b) -> Expect abt b #

(>>) :: Expect abt a -> Expect abt b -> Expect abt b #

return :: a -> Expect abt a #

fail :: String -> Expect abt a #

Functor (Expect abt) Source # 

Methods

fmap :: (a -> b) -> Expect abt a -> Expect abt b #

(<$) :: a -> Expect abt b -> Expect abt a #

Applicative (Expect abt) Source # 

Methods

pure :: a -> Expect abt a #

(<*>) :: Expect abt (a -> b) -> Expect abt a -> Expect abt b #

(*>) :: Expect abt a -> Expect abt b -> Expect abt b #

(<*) :: Expect abt a -> Expect abt b -> Expect abt a #

runExpect :: forall abt f a. (ABT Term abt, Foldable f) => Expect abt (abt '[] a) -> abt '[a] HProb -> f (Some2 abt) -> abt '[] HProb Source #

Run a computation in the Expect monad, residualizing out all the statements in the final evaluation context. The second argument should include all the terms altered by the Eval expression; this is necessary to ensure proper hygiene; for example(s):

runExpect (pureEvaluate e) [Some2 e]

We use Some2 on the inputs because it doesn't matter what their type or locally-bound variables are, so we want to allow f to contain terms with different indices.

residualizeExpectListContext :: forall abt. ABT Term abt => abt '[] HProb -> ListContext abt ExpectP -> abt '[] HProb Source #

TODO: IntMap-based version

...

emit :: ABT Term abt => Text -> Sing a -> (abt '[a] HProb -> abt '[] HProb) -> Expect abt (Variable a) Source #

emit_ :: ABT Term abt => (abt '[] HProb -> abt '[] HProb) -> Expect abt () Source #