Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
Lazy partial evaluation.
BUG: completely gave up on structure sharing. Need to add that
back in. cf., gvidal-lopstr07lncs.pdf
for an approach much
like my old one.
- type TermEvaluator abt m = forall a. abt '[] a -> m (Whnf abt a)
- type MeasureEvaluator abt m = forall a. abt '[] (HMeasure a) -> m (Whnf abt a)
- type CaseEvaluator abt m = forall a b. abt '[] a -> [Branch a abt b] -> m (Whnf abt b)
- type VariableEvaluator abt m = forall a. Variable a -> m (Whnf abt a)
- evaluate :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => MeasureEvaluator abt m -> (TermEvaluator abt m -> CaseEvaluator abt m) -> TermEvaluator abt m
- update :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => MeasureEvaluator abt m -> TermEvaluator abt m -> VariableEvaluator abt m
- defaultCaseEvaluator :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => TermEvaluator abt m -> CaseEvaluator abt m
- toStatements :: Assocs (abt '[]) -> [Statement abt p]
- class Interp a a' | a -> a' where
- reifyPair :: ABT Term abt => Head abt (HPair a b) -> (abt '[] a, abt '[] b)
Lazy partial evaluation
type TermEvaluator abt m = forall a. abt '[] a -> m (Whnf abt a) Source #
A function for evaluating any term to weak-head normal form.
type MeasureEvaluator abt m = forall a. abt '[] (HMeasure a) -> m (Whnf abt a) Source #
A function for "performing" an HMeasure
monadic action.
This could mean actual random sampling, or simulated sampling
by generating a new term and returning the newly bound variable,
or anything else.
type CaseEvaluator abt m = forall a b. abt '[] a -> [Branch a abt b] -> m (Whnf abt b) Source #
A function for evaluating any case-expression to weak-head normal form.
type VariableEvaluator abt m = forall a. Variable a -> m (Whnf abt a) Source #
A function for evaluating any variable to weak-head normal form.
evaluate :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => MeasureEvaluator abt m -> (TermEvaluator abt m -> CaseEvaluator abt m) -> TermEvaluator abt m Source #
Lazy partial evaluation with some given "perform" and
"evaluateCase" functions. The first argument to evaluateCase
will be the TermEvaluator
we're constructing (thus tying the
knot). N.B., if p ~ 'Pure
then the "perform" function will
never be called.
We factor out the CaseEvaluator
because some code (e.g.,
disintegration) may need to do something special rather than
just relying on the defaultCaseEvaluator
implementation.
Helper functions
update :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => MeasureEvaluator abt m -> TermEvaluator abt m -> VariableEvaluator abt m Source #
defaultCaseEvaluator :: forall abt m p. (ABT Term abt, EvaluationMonad abt m p) => TermEvaluator abt m -> CaseEvaluator abt m Source #
A simple CaseEvaluator
which uses the DatumEvaluator
to
force the scrutinee, and if matchBranches
succeeds then we
call the TermEvaluator
to continue evaluating the body of the
matched branch. If we GotStuck
then we return a Neutral
term
of the case expression itself (n.b, any side effects from having
called the DatumEvaluator
will still persist when returning
this neutral term). If we didn't get stuck and yet none of the
branches matches, then we throw an exception.
toStatements :: Assocs (abt '[]) -> [Statement abt p] Source #