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

Contents

Description

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.

Synopsis

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 #

Helpers that should really go away

class Interp a a' | a -> a' where Source #

Minimal complete definition

reify, reflect

Methods

reify :: ABT Term abt => Head abt a -> a' Source #

reflect :: ABT Term abt => a' -> Head abt a Source #

reifyPair :: ABT Term abt => Head abt (HPair a b) -> (abt '[] a, abt '[] b) Source #