diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res index d026765d..62bd54a1 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res @@ -5,6 +5,8 @@ type errorValue = | RERecordPropertyNotFound(string, string) | RETodo(string) // To do +type t = errorValue + let showError = err => switch err { | REArrayIndexNotFound(msg, index) => `${msg}: ${Js.String.make(index)}` diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res index e1b0d079..bb2500ca 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res @@ -8,6 +8,7 @@ open Reducer_ErrorValue type expression = T.expression type expressionValue = ExpressionValue.expressionValue +type t = expression /* Shows the Lisp Code as text lisp code @@ -31,10 +32,10 @@ let showResult = codeResult => /* Converts a MathJs code to Lisp Code */ -let parse_ = (expr: string, parser, converter): result => +let parse_ = (expr: string, parser, converter): result => expr->parser->Result.flatMap(node => converter(node)) -let parse = (mathJsCode: string): result => +let parse = (mathJsCode: string): result => mathJsCode->parse_(MathJs.Parse.parse, MathJs.ToExpression.fromNode) module MapString = Belt.Map.String @@ -54,7 +55,7 @@ let reduceValueList = (valueList: list): result => +let rec reduceExpression = (expression: t, bindings): result => switch expression { | T.EValue(value) => value->Ok | T.EList(list) => { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.resi b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.resi new file mode 100644 index 00000000..1d4c5281 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.resi @@ -0,0 +1,33 @@ +module Result = Belt.Result +module T = Reducer_Expression_T +type expression = T.expression +type expressionValue = ReducerInterface.ExpressionValue.expressionValue +type t = expression +let show: T.expression => Js.String.t +let showResult: result => string +let parse_: ( + string, + string => Result.t<'a, Reducer_ErrorValue.t>, + 'a => Result.t, +) => result +let parse: string => result +module MapString = Belt.Map.String +type bindings = MapString.t +let defaultBindings: bindings +let reduceValueList: list => result< + expressionValue, + Reducer_ErrorValue.t, +> +let reduceExpression: (expression, 'a) => result< + expressionValue, + Reducer_ErrorValue.t, +> +let evalWBindingsExpression: (expression, 'a) => result< + expressionValue, + Reducer_ErrorValue.t, +> +let evalWBindings: (string, bindings) => Result.t< + expressionValue, + Reducer_ErrorValue.t, +> +let eval: string => Result.t