Fix for functions
This commit is contained in:
parent
65f1485a55
commit
ac0baf94ed
|
@ -335,7 +335,7 @@ let toLeaf =
|
||||||
FloatFromDist.operationToLeaf(evaluationParams, distToFloatOp, t)
|
FloatFromDist.operationToLeaf(evaluationParams, distToFloatOp, t)
|
||||||
| `Normalize(t) => Normalize.operationToLeaf(evaluationParams, t)
|
| `Normalize(t) => Normalize.operationToLeaf(evaluationParams, t)
|
||||||
| `Render(t) => Render.operationToLeaf(evaluationParams, t)
|
| `Render(t) => Render.operationToLeaf(evaluationParams, t)
|
||||||
| `Function(t) => Ok(`Function(t))
|
| `Function(_) => Error("Function must be called with params")
|
||||||
| `Symbol(r) => ExpressionTypes.ExpressionTree.Environment.get(evaluationParams.environment, r) |> E.O.toResult("Undeclared variable " ++ r)
|
| `Symbol(r) => ExpressionTypes.ExpressionTree.Environment.get(evaluationParams.environment, r) |> E.O.toResult("Undeclared variable " ++ r)
|
||||||
| `FunctionCall(name, args) =>
|
| `FunctionCall(name, args) =>
|
||||||
callableFunction(evaluationParams, name, args)
|
callableFunction(evaluationParams, name, args)
|
||||||
|
|
|
@ -79,7 +79,8 @@ let fnn =
|
||||||
evaluationParams: ExpressionTypes.ExpressionTree.evaluationParams,
|
evaluationParams: ExpressionTypes.ExpressionTree.evaluationParams,
|
||||||
name,
|
name,
|
||||||
args: array(node),
|
args: array(node),
|
||||||
) =>
|
) =>{
|
||||||
|
Js.log3("HERE", name, args);
|
||||||
switch (
|
switch (
|
||||||
name,
|
name,
|
||||||
ExpressionTypes.ExpressionTree.Environment.get(
|
ExpressionTypes.ExpressionTree.Environment.get(
|
||||||
|
@ -120,3 +121,4 @@ let fnn =
|
||||||
| ("to", _) => to_(args)
|
| ("to", _) => to_(args)
|
||||||
| _ => Error("Function not found")
|
| _ => Error("Function not found")
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
[%%debugger.chrome]
|
||||||
module MathJsonToMathJsAdt = {
|
module MathJsonToMathJsAdt = {
|
||||||
type arg =
|
type arg =
|
||||||
| Symbol(string)
|
| Symbol(string)
|
||||||
|
@ -355,6 +356,7 @@ let fromString2 = str => {
|
||||||
Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered.
|
Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered.
|
||||||
*/
|
*/
|
||||||
let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath;
|
let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath;
|
||||||
|
Js.log2("HI", mathJsToJson);
|
||||||
let mathJsParse =
|
let mathJsParse =
|
||||||
E.R.bind(mathJsToJson, r => {
|
E.R.bind(mathJsToJson, r => {
|
||||||
switch (MathJsonToMathJsAdt.run(r)) {
|
switch (MathJsonToMathJsAdt.run(r)) {
|
||||||
|
@ -364,6 +366,7 @@ let fromString2 = str => {
|
||||||
});
|
});
|
||||||
|
|
||||||
let value = E.R.bind(mathJsParse, MathAdtToDistDst.run);
|
let value = E.R.bind(mathJsParse, MathAdtToDistDst.run);
|
||||||
|
Js.log3("HI", mathJsParse, value);
|
||||||
value;
|
value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ module Inputs = {
|
||||||
type inputs = {
|
type inputs = {
|
||||||
distPlusIngredients: ingredients,
|
distPlusIngredients: ingredients,
|
||||||
samplingInputs: SamplingInputs.t,
|
samplingInputs: SamplingInputs.t,
|
||||||
environment: ExpressionTypes.ExpressionTree.environment
|
environment: ExpressionTypes.ExpressionTree.environment,
|
||||||
};
|
};
|
||||||
|
|
||||||
let empty: SamplingInputs.t = {
|
let empty: SamplingInputs.t = {
|
||||||
|
@ -67,16 +67,14 @@ module Internals = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let addVariable =
|
let addVariable =
|
||||||
(
|
({samplingInputs, guesstimatorString, environment}: inputs, str, node)
|
||||||
{samplingInputs, guesstimatorString, environment}: inputs,
|
|
||||||
str,
|
|
||||||
node,
|
|
||||||
)
|
|
||||||
: inputs => {
|
: inputs => {
|
||||||
samplingInputs,
|
samplingInputs,
|
||||||
guesstimatorString,
|
guesstimatorString,
|
||||||
environment:
|
environment:
|
||||||
ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ => Some(node))
|
ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ =>
|
||||||
|
Some(node)
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => {
|
let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => {
|
||||||
|
@ -110,14 +108,15 @@ module Internals = {
|
||||||
let runProgram = (inputs: inputs, p: ExpressionTypes.Program.program) => {
|
let runProgram = (inputs: inputs, p: ExpressionTypes.Program.program) => {
|
||||||
let ins = ref(inputs);
|
let ins = ref(inputs);
|
||||||
p
|
p
|
||||||
|> E.A.fmap(statement =>
|
|> E.A.fmap(statement => {
|
||||||
|
Js.log2("Running ling", statement);
|
||||||
switch (statement) {
|
switch (statement) {
|
||||||
| `Assignment(name, node) =>
|
| `Assignment(name, node) =>
|
||||||
ins := addVariable(ins^, name, node);
|
ins := addVariable(ins^, name, node);
|
||||||
None;
|
None;
|
||||||
| `Expression(node) => Some(runNode(ins^, node))
|
| `Expression(node) => Some(runNode(ins^, node))
|
||||||
}
|
};
|
||||||
)
|
})
|
||||||
|> E.A.O.concatSomes
|
|> E.A.O.concatSomes
|
||||||
|> E.A.R.firstErrorOrOpen;
|
|> E.A.R.firstErrorOrOpen;
|
||||||
};
|
};
|
||||||
|
@ -125,7 +124,12 @@ module Internals = {
|
||||||
let inputsToShape = (inputs: inputs) => {
|
let inputsToShape = (inputs: inputs) => {
|
||||||
MathJsParser.fromString(inputs.guesstimatorString)
|
MathJsParser.fromString(inputs.guesstimatorString)
|
||||||
|> E.R.bind(_, g => runProgram(inputs, g))
|
|> E.R.bind(_, g => runProgram(inputs, g))
|
||||||
|> E.R.bind(_, r => E.A.last(r) |> E.O.toResult("No rendered lines") |> E.R.fmap(Shape.T.normalize));
|
|> E.R.bind(_, r =>
|
||||||
|
E.A.last(r)
|
||||||
|
|> E.O.toResult("No rendered lines")
|
||||||
|
|> (e => {Js.log2("EE", e); e})
|
||||||
|
|> E.R.fmap(Shape.T.normalize)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) => {
|
let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user