Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
- pureEvaluate :: ABT Term abt => TermEvaluator abt (Expect abt)
- data ListContext abt p = ListContext {
- nextFreshNat :: !Nat
- statements :: [Statement abt p]
- type ExpectAns abt = ListContext abt ExpectP -> abt '[] HProb
- newtype Expect abt x = Expect {}
- runExpect :: forall abt f a. (ABT Term abt, Foldable f) => Expect abt (abt '[] a) -> abt '[a] HProb -> f (Some2 abt) -> abt '[] HProb
- residualizeExpectListContext :: forall abt. ABT Term abt => abt '[] HProb -> ListContext abt ExpectP -> abt '[] HProb
- emit :: ABT Term abt => Text -> Sing a -> (abt '[a] HProb -> abt '[] HProb) -> Expect abt (Variable a)
- emit_ :: ABT Term abt => (abt '[] HProb -> abt '[] HProb) -> Expect abt ()
Documentation
pureEvaluate :: ABT Term abt => TermEvaluator abt (Expect abt) Source #
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.)
ListContext | |
|
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 #