Added evaluateAndRetry function

This commit is contained in:
Ozzie Gooen 2020-07-08 13:52:47 +01:00
parent 9d0ecda297
commit 248545ee34
2 changed files with 14 additions and 16 deletions

View File

@ -174,10 +174,7 @@ module Normalize = {
| `RenderedDist(s) =>
Ok(`RenderedDist(Distributions.Shape.T.normalize(s)))
| `SymbolicDist(_) => Ok(t)
| _ =>
t
|> evaluateNode(evaluationParams)
|> E.R.bind(_, operationToLeaf(evaluationParams))
| _ => evaluateAndRetry(evaluationParams, operationToLeaf, t)
};
};
};
@ -195,8 +192,9 @@ module FloatFromDist = {
|> (v => Ok(`SymbolicDist(`Float(v))))
| _ =>
t
|> evaluateNode(evaluationParams)
|> E.R.bind(_, operationToLeaf(evaluationParams, distToFloatOp))
|> evaluateAndRetry(evaluationParams, r =>
operationToLeaf(r, distToFloatOp)
)
};
};
};
@ -212,10 +210,7 @@ module Render = {
),
)
| `RenderedDist(_) as t => Ok(t) // already a rendered shape, we're done here
| _ =>
t
|> evaluateNode(evaluationParams)
|> E.R.bind(_, operationToLeaf(evaluationParams))
| _ => evaluateAndRetry(evaluationParams, operationToLeaf, t)
};
};
};

View File

@ -19,7 +19,7 @@ module ExpressionTree = {
type dist = [
| `SymbolicDist(SymbolicTypes.symbolicDist)
| `RenderedDist(DistTypes.shape)
]
];
type evaluationParams = {
sampleCount: int,
@ -31,6 +31,9 @@ module ExpressionTree = {
let render = (evaluationParams: evaluationParams, r) =>
evaluateNode(evaluationParams, `Render(r));
let evaluateAndRetry = (evaluationParams, fn, node) =>
node |> evaluationParams.evaluateNode(evaluationParams) |> E.R.bind(_, fn(evaluationParams));
};
type simplificationResult = [