format
This commit is contained in:
parent
992dd92d9b
commit
bbe8eced29
|
@ -21,7 +21,7 @@ let callInternal = (call: functionCall, _environment): result<'b, errorValue> =>
|
||||||
}
|
}
|
||||||
|
|
||||||
let constructRecord = arrayOfPairs => {
|
let constructRecord = arrayOfPairs => {
|
||||||
Belt.Array.map(arrayOfPairs, pairValue =>
|
Belt.Array.map(arrayOfPairs, pairValue =>
|
||||||
switch pairValue {
|
switch pairValue {
|
||||||
| EvArray([EvString(key), valueValue]) => (key, valueValue)
|
| EvArray([EvString(key), valueValue]) => (key, valueValue)
|
||||||
| _ => ("wrong key type", pairValue->toStringWithType->EvString)
|
| _ => ("wrong key type", pairValue->toStringWithType->EvString)
|
||||||
|
|
|
@ -19,7 +19,7 @@ let dispatchMacroCall = (
|
||||||
environment,
|
environment,
|
||||||
reduceExpression: ExpressionT.reducerFn,
|
reduceExpression: ExpressionT.reducerFn,
|
||||||
): result<expression, errorValue> => {
|
): result<expression, errorValue> => {
|
||||||
let doBindStatement = (bindingExpr: expression, statement: expression, environment) =>
|
let doBindStatement = (bindingExpr: expression, statement: expression, environment) =>
|
||||||
switch statement {
|
switch statement {
|
||||||
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
||||||
let rExternalBindingsValue = reduceExpression(bindingExpr, bindings, environment)
|
let rExternalBindingsValue = reduceExpression(bindingExpr, bindings, environment)
|
||||||
|
@ -37,9 +37,8 @@ let dispatchMacroCall = (
|
||||||
}
|
}
|
||||||
| _ => REAssignmentExpected->Error
|
| _ => REAssignmentExpected->Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let doBindExpression = (bindingExpr: expression, statement: expression, environment) =>
|
let doBindExpression = (bindingExpr: expression, statement: expression, environment) =>
|
||||||
switch statement {
|
switch statement {
|
||||||
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
||||||
let rExternalBindingsValue = reduceExpression(
|
let rExternalBindingsValue = reduceExpression(
|
||||||
|
@ -74,7 +73,7 @@ let dispatchMacroCall = (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let doBlock = (exprs: list<expression>, _bindings: ExpressionT.bindings, _environment): result<
|
let doBlock = (exprs: list<expression>, _bindings: ExpressionT.bindings, _environment): result<
|
||||||
expression,
|
expression,
|
||||||
errorValue,
|
errorValue,
|
||||||
|
|
|
@ -32,7 +32,7 @@ let parse = (mathJsCode: string): result<t, errorValue> =>
|
||||||
let rec reduceExpression = (expression: t, bindings: T.bindings, environment: environment): result<
|
let rec reduceExpression = (expression: t, bindings: T.bindings, environment: environment): result<
|
||||||
expressionValue,
|
expressionValue,
|
||||||
'e,
|
'e,
|
||||||
> =>
|
> =>
|
||||||
switch expression {
|
switch expression {
|
||||||
| T.EValue(value) => value->Ok
|
| T.EValue(value) => value->Ok
|
||||||
| T.EList(list) =>
|
| T.EList(list) =>
|
||||||
|
@ -119,10 +119,15 @@ let evaluatePartialUsingExternalBindings = (
|
||||||
externalBindings: ReducerInterface_ExpressionValue.externalBindings,
|
externalBindings: ReducerInterface_ExpressionValue.externalBindings,
|
||||||
environment: ReducerInterface_ExpressionValue.environment,
|
environment: ReducerInterface_ExpressionValue.environment,
|
||||||
): result<externalBindings, errorValue> => {
|
): result<externalBindings, errorValue> => {
|
||||||
let rAnswer = evaluateUsingOptions(~environment=Some(environment), ~externalBindings=Some(externalBindings), code)
|
let rAnswer = evaluateUsingOptions(
|
||||||
|
~environment=Some(environment),
|
||||||
|
~externalBindings=Some(externalBindings),
|
||||||
|
code,
|
||||||
|
)
|
||||||
switch rAnswer {
|
switch rAnswer {
|
||||||
| Ok(EvRecord(externalBindings)) => Ok(externalBindings)
|
| Ok(EvRecord(externalBindings)) => Ok(externalBindings)
|
||||||
| Ok(_) => Error(Reducer_ErrorValue.RESyntaxError(`Partials must end with an assignment or record`))
|
| Ok(_) =>
|
||||||
| Error(err) => err->Error
|
Error(Reducer_ErrorValue.RESyntaxError(`Partials must end with an assignment or record`))
|
||||||
|
| Error(err) => err->Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,10 @@ external castString: unit => string = "%identity"
|
||||||
/*
|
/*
|
||||||
As JavaScript returns us any type, we need to type check and cast type propertype before using it
|
As JavaScript returns us any type, we need to type check and cast type propertype before using it
|
||||||
*/
|
*/
|
||||||
let jsToEv = (jsValue): result<expressionValue, errorValue> =>
|
let jsToEv = (jsValue): result<expressionValue, errorValue> =>
|
||||||
switch Js.typeof(jsValue) {
|
switch Js.typeof(jsValue) {
|
||||||
| "boolean" => jsValue->castBool->EvBool->Ok
|
| "boolean" => jsValue->castBool->EvBool->Ok
|
||||||
| "number" => jsValue->castNumber->EvNumber->Ok
|
| "number" => jsValue->castNumber->EvNumber->Ok
|
||||||
| "string" => jsValue->castString->EvString->Ok
|
| "string" => jsValue->castString->EvString->Ok
|
||||||
| other => RETodo(`Unhandled MathJs literal type: ${Js.String.make(other)}`)->Error
|
| other => RETodo(`Unhandled MathJs literal type: ${Js.String.make(other)}`)->Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,13 @@ module Helpers = {
|
||||||
let catchAndConvertTwoArgsToDists = (args: array<expressionValue>): option<(
|
let catchAndConvertTwoArgsToDists = (args: array<expressionValue>): option<(
|
||||||
DistributionTypes.genericDist,
|
DistributionTypes.genericDist,
|
||||||
DistributionTypes.genericDist,
|
DistributionTypes.genericDist,
|
||||||
)> =>
|
)> =>
|
||||||
switch args {
|
switch args {
|
||||||
| [EvDistribution(a), EvDistribution(b)] => Some((a, b))
|
| [EvDistribution(a), EvDistribution(b)] => Some((a, b))
|
||||||
| [EvNumber(a), EvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
|
| [EvNumber(a), EvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
|
||||||
| [EvDistribution(a), EvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
|
| [EvDistribution(a), EvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let toFloatFn = (
|
let toFloatFn = (
|
||||||
fnCall: DistributionTypes.DistributionOperation.toFloat,
|
fnCall: DistributionTypes.DistributionOperation.toFloat,
|
||||||
|
@ -119,7 +118,7 @@ module Helpers = {
|
||||||
mixtureWithGivenWeights(distributions, weights)
|
mixtureWithGivenWeights(distributions, weights)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
|
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
|
||||||
switch E.A.last(args) {
|
switch E.A.last(args) {
|
||||||
| Some(EvArray(b)) => {
|
| Some(EvArray(b)) => {
|
||||||
let weights = parseNumberArray(b)
|
let weights = parseNumberArray(b)
|
||||||
|
@ -138,7 +137,6 @@ module Helpers = {
|
||||||
}
|
}
|
||||||
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
|
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module SymbolicConstructors = {
|
module SymbolicConstructors = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user