Iev -> IEv Just more readable prefix
This commit is contained in:
parent
24a9c52789
commit
07d5c6d8b3
|
@ -26,14 +26,14 @@ describe("bindStatement", () => {
|
||||||
// Now let's feed a binding to see what happens
|
// Now let's feed a binding to see what happens
|
||||||
testMacro(
|
testMacro(
|
||||||
[],
|
[],
|
||||||
eBindStatement(eBindings([("x", IevNumber(2.))]), exampleStatementX),
|
eBindStatement(eBindings([("x", IEvNumber(2.))]), exampleStatementX),
|
||||||
"Ok((:$_setBindings_$ @{x: 2} :y 2) context: @{x: 2})",
|
"Ok((:$_setBindings_$ @{x: 2} :y 2) context: @{x: 2})",
|
||||||
)
|
)
|
||||||
// An expression does not return a binding, thus error
|
// An expression does not return a binding, thus error
|
||||||
testMacro([], eBindStatement(eBindings([]), exampleExpression), "Assignment expected")
|
testMacro([], eBindStatement(eBindings([]), exampleExpression), "Assignment expected")
|
||||||
// When bindings from previous statement are missing the context is injected. This must be the first statement of a block
|
// When bindings from previous statement are missing the context is injected. This must be the first statement of a block
|
||||||
testMacro(
|
testMacro(
|
||||||
[("z", IevNumber(99.))],
|
[("z", IEvNumber(99.))],
|
||||||
eBindStatementDefault(exampleStatementY),
|
eBindStatementDefault(exampleStatementY),
|
||||||
"Ok((:$_setBindings_$ @{z: 99} :y 1) context: @{z: 99})",
|
"Ok((:$_setBindings_$ @{z: 99} :y 1) context: @{z: 99})",
|
||||||
)
|
)
|
||||||
|
@ -43,24 +43,24 @@ describe("bindExpression", () => {
|
||||||
// x is simply bound in the expression
|
// x is simply bound in the expression
|
||||||
testMacro(
|
testMacro(
|
||||||
[],
|
[],
|
||||||
eBindExpression(eBindings([("x", IevNumber(2.))]), eSymbol("x")),
|
eBindExpression(eBindings([("x", IEvNumber(2.))]), eSymbol("x")),
|
||||||
"Ok(2 context: @{x: 2})",
|
"Ok(2 context: @{x: 2})",
|
||||||
)
|
)
|
||||||
// When an let statement is the end expression then bindings are returned
|
// When an let statement is the end expression then bindings are returned
|
||||||
testMacro(
|
testMacro(
|
||||||
[],
|
[],
|
||||||
eBindExpression(eBindings([("x", IevNumber(2.))]), exampleStatementY),
|
eBindExpression(eBindings([("x", IEvNumber(2.))]), exampleStatementY),
|
||||||
"Ok((:$_exportBindings_$ (:$_setBindings_$ @{x: 2} :y 1)) context: @{x: 2})",
|
"Ok((:$_exportBindings_$ (:$_setBindings_$ @{x: 2} :y 1)) context: @{x: 2})",
|
||||||
)
|
)
|
||||||
// Now let's reduce that expression
|
// Now let's reduce that expression
|
||||||
testMacroEval(
|
testMacroEval(
|
||||||
[],
|
[],
|
||||||
eBindExpression(eBindings([("x", IevNumber(2.))]), exampleStatementY),
|
eBindExpression(eBindings([("x", IEvNumber(2.))]), exampleStatementY),
|
||||||
"Ok(@{x: 2,y: 1})",
|
"Ok(@{x: 2,y: 1})",
|
||||||
)
|
)
|
||||||
// When bindings are missing the context is injected. This must be the first and last statement of a block
|
// When bindings are missing the context is injected. This must be the first and last statement of a block
|
||||||
testMacroEval(
|
testMacroEval(
|
||||||
[("z", IevNumber(99.))],
|
[("z", IEvNumber(99.))],
|
||||||
eBindExpressionDefault(exampleStatementY),
|
eBindExpressionDefault(exampleStatementY),
|
||||||
"Ok(@{y: 1,z: 99})",
|
"Ok(@{y: 1,z: 99})",
|
||||||
)
|
)
|
||||||
|
@ -115,7 +115,7 @@ describe("block", () => {
|
||||||
"Ok((:$$_bindExpression_$$ {(:$_let_$ :y (:add :x 1)); :y}))",
|
"Ok((:$$_bindExpression_$$ {(:$_let_$ :y (:add :x 1)); :y}))",
|
||||||
)
|
)
|
||||||
testMacroEval(
|
testMacroEval(
|
||||||
[("x", IevNumber(1.))],
|
[("x", IEvNumber(1.))],
|
||||||
eBlock(list{
|
eBlock(list{
|
||||||
eBlock(list{
|
eBlock(list{
|
||||||
eLetStatement("y", eFunction("add", list{eSymbol("x"), eNumber(1.)})),
|
eLetStatement("y", eFunction("add", list{eSymbol("x"), eNumber(1.)})),
|
||||||
|
@ -135,12 +135,12 @@ describe("lambda", () => {
|
||||||
testMacro([], callLambdaExpression, "Ok(((:$$_lambda_$$ [y] :y) 1))")
|
testMacro([], callLambdaExpression, "Ok(((:$$_lambda_$$ [y] :y) 1))")
|
||||||
testMacroEval([], callLambdaExpression, "Ok(1)")
|
testMacroEval([], callLambdaExpression, "Ok(1)")
|
||||||
// Parameters shadow the outer scope
|
// Parameters shadow the outer scope
|
||||||
testMacroEval([("y", IevNumber(666.))], callLambdaExpression, "Ok(1)")
|
testMacroEval([("y", IEvNumber(666.))], callLambdaExpression, "Ok(1)")
|
||||||
// When not shadowed by the parameters, the outer scope variables are available
|
// When not shadowed by the parameters, the outer scope variables are available
|
||||||
let lambdaExpression = eFunction(
|
let lambdaExpression = eFunction(
|
||||||
"$$_lambda_$$",
|
"$$_lambda_$$",
|
||||||
list{eArrayString(["z"]), eFunction("add", list{eSymbol("y"), eSymbol("z")})},
|
list{eArrayString(["z"]), eFunction("add", list{eSymbol("y"), eSymbol("z")})},
|
||||||
)
|
)
|
||||||
let callLambdaExpression = eList(list{lambdaExpression, eNumber(1.)})
|
let callLambdaExpression = eList(list{lambdaExpression, eNumber(1.)})
|
||||||
testMacroEval([("y", IevNumber(666.))], callLambdaExpression, "Ok(667)")
|
testMacroEval([("y", IEvNumber(666.))], callLambdaExpression, "Ok(667)")
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,11 +6,11 @@ module Module = Reducer_Category_Module
|
||||||
|
|
||||||
let removeDefaultsInternal = (iev: InternalExpressionValue.expressionValue) => {
|
let removeDefaultsInternal = (iev: InternalExpressionValue.expressionValue) => {
|
||||||
switch iev {
|
switch iev {
|
||||||
| InternalExpressionValue.IevModule(nameSpace) =>
|
| InternalExpressionValue.IEvModule(nameSpace) =>
|
||||||
Module.removeOther(
|
Module.removeOther(
|
||||||
nameSpace,
|
nameSpace,
|
||||||
ReducerInterface.StdLib.internalStdLib,
|
ReducerInterface.StdLib.internalStdLib,
|
||||||
)->InternalExpressionValue.IevModule
|
)->InternalExpressionValue.IEvModule
|
||||||
| value => value
|
| value => value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ open Jest
|
||||||
open ExpectJs
|
open ExpectJs
|
||||||
|
|
||||||
describe("eval", () => {
|
describe("eval", () => {
|
||||||
test("Number", () => expect(MathJs.Eval.eval("1"))->toEqual(Ok(IevNumber(1.))))
|
test("Number", () => expect(MathJs.Eval.eval("1"))->toEqual(Ok(IEvNumber(1.))))
|
||||||
test("Number expr", () => expect(MathJs.Eval.eval("1-1"))->toEqual(Ok(IevNumber(0.))))
|
test("Number expr", () => expect(MathJs.Eval.eval("1-1"))->toEqual(Ok(IEvNumber(0.))))
|
||||||
test("String", () => expect(MathJs.Eval.eval("'hello'"))->toEqual(Ok(IevString("hello"))))
|
test("String", () => expect(MathJs.Eval.eval("'hello'"))->toEqual(Ok(IEvString("hello"))))
|
||||||
test("String expr", () =>
|
test("String expr", () =>
|
||||||
expect(MathJs.Eval.eval("concat('hello ','world')"))->toEqual(Ok(IevString("hello world")))
|
expect(MathJs.Eval.eval("concat('hello ','world')"))->toEqual(Ok(IEvString("hello world")))
|
||||||
)
|
)
|
||||||
test("Boolean", () => expect(MathJs.Eval.eval("true"))->toEqual(Ok(IevBool(true))))
|
test("Boolean", () => expect(MathJs.Eval.eval("true"))->toEqual(Ok(IEvBool(true))))
|
||||||
test("Boolean expr", () => expect(MathJs.Eval.eval("2>1"))->toEqual(Ok(IevBool(true))))
|
test("Boolean expr", () => expect(MathJs.Eval.eval("2>1"))->toEqual(Ok(IEvBool(true))))
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("errors", () => {
|
describe("errors", () => {
|
||||||
|
|
|
@ -75,13 +75,13 @@ module FRType = {
|
||||||
|
|
||||||
let rec toFrValue = (r: expressionValue): option<frValue> =>
|
let rec toFrValue = (r: expressionValue): option<frValue> =>
|
||||||
switch r {
|
switch r {
|
||||||
| IevNumber(f) => Some(FRValueNumber(f))
|
| IEvNumber(f) => Some(FRValueNumber(f))
|
||||||
| IevString(f) => Some(FRValueString(f))
|
| IEvString(f) => Some(FRValueString(f))
|
||||||
| IevDistribution(f) => Some(FRValueDistOrNumber(FRValueDist(f)))
|
| IEvDistribution(f) => Some(FRValueDistOrNumber(FRValueDist(f)))
|
||||||
| IevLambda(f) => Some(FRValueLambda(f))
|
| IEvLambda(f) => Some(FRValueLambda(f))
|
||||||
| IevArray(elements) =>
|
| IEvArray(elements) =>
|
||||||
elements->E.A2.fmap(toFrValue)->E.A.O.openIfAllSome->E.O2.fmap(r => FRValueArray(r))
|
elements->E.A2.fmap(toFrValue)->E.A.O.openIfAllSome->E.O2.fmap(r => FRValueArray(r))
|
||||||
| IevRecord(map) =>
|
| IEvRecord(map) =>
|
||||||
Belt.Map.String.toArray(map)
|
Belt.Map.String.toArray(map)
|
||||||
->E.A2.fmap(((key, item)) => item->toFrValue->E.O2.fmap(o => (key, o)))
|
->E.A2.fmap(((key, item)) => item->toFrValue->E.O2.fmap(o => (key, o)))
|
||||||
->E.A.O.openIfAllSome
|
->E.A.O.openIfAllSome
|
||||||
|
@ -92,26 +92,26 @@ module FRType = {
|
||||||
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> =>
|
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> =>
|
||||||
switch (t, r) {
|
switch (t, r) {
|
||||||
| (FRTypeAny, f) => toFrValue(f)
|
| (FRTypeAny, f) => toFrValue(f)
|
||||||
| (FRTypeString, IevString(f)) => Some(FRValueString(f))
|
| (FRTypeString, IEvString(f)) => Some(FRValueString(f))
|
||||||
| (FRTypeNumber, IevNumber(f)) => Some(FRValueNumber(f))
|
| (FRTypeNumber, IEvNumber(f)) => Some(FRValueNumber(f))
|
||||||
| (FRTypeDistOrNumber, IevNumber(f)) => Some(FRValueDistOrNumber(FRValueNumber(f)))
|
| (FRTypeDistOrNumber, IEvNumber(f)) => Some(FRValueDistOrNumber(FRValueNumber(f)))
|
||||||
| (FRTypeDistOrNumber, IevDistribution(Symbolic(#Float(f)))) =>
|
| (FRTypeDistOrNumber, IEvDistribution(Symbolic(#Float(f)))) =>
|
||||||
Some(FRValueDistOrNumber(FRValueNumber(f)))
|
Some(FRValueDistOrNumber(FRValueNumber(f)))
|
||||||
| (FRTypeDistOrNumber, IevDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f)))
|
| (FRTypeDistOrNumber, IEvDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f)))
|
||||||
| (FRTypeNumeric, IevNumber(f)) => Some(FRValueNumber(f))
|
| (FRTypeNumeric, IEvNumber(f)) => Some(FRValueNumber(f))
|
||||||
| (FRTypeNumeric, IevDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
|
| (FRTypeNumeric, IEvDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
|
||||||
| (FRTypeLambda, IevLambda(f)) => Some(FRValueLambda(f))
|
| (FRTypeLambda, IEvLambda(f)) => Some(FRValueLambda(f))
|
||||||
| (FRTypeArray(intendedType), IevArray(elements)) => {
|
| (FRTypeArray(intendedType), IEvArray(elements)) => {
|
||||||
let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
|
let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
|
||||||
E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
|
E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
|
||||||
}
|
}
|
||||||
| (FRTypeDict(r), IevRecord(map)) =>
|
| (FRTypeDict(r), IEvRecord(map)) =>
|
||||||
map
|
map
|
||||||
->Belt.Map.String.toArray
|
->Belt.Map.String.toArray
|
||||||
->E.A2.fmap(((key, item)) => matchWithExpressionValue(r, item)->E.O2.fmap(o => (key, o)))
|
->E.A2.fmap(((key, item)) => matchWithExpressionValue(r, item)->E.O2.fmap(o => (key, o)))
|
||||||
->E.A.O.openIfAllSome
|
->E.A.O.openIfAllSome
|
||||||
->E.O2.fmap(r => FRValueDict(Js.Dict.fromArray(r)))
|
->E.O2.fmap(r => FRValueDict(Js.Dict.fromArray(r)))
|
||||||
| (FRTypeRecord(recordParams), IevRecord(map)) => {
|
| (FRTypeRecord(recordParams), IEvRecord(map)) => {
|
||||||
let getAndMatch = (name, input) =>
|
let getAndMatch = (name, input) =>
|
||||||
Belt.Map.String.get(map, name)->E.O.bind(matchWithExpressionValue(input))
|
Belt.Map.String.get(map, name)->E.O.bind(matchWithExpressionValue(input))
|
||||||
//All names in the type must be present. If any are missing, the corresponding
|
//All names in the type must be present. If any are missing, the corresponding
|
||||||
|
@ -127,17 +127,17 @@ module FRType = {
|
||||||
|
|
||||||
let rec matchReverse = (e: frValue): expressionValue =>
|
let rec matchReverse = (e: frValue): expressionValue =>
|
||||||
switch e {
|
switch e {
|
||||||
| FRValueNumber(f) => IevNumber(f)
|
| FRValueNumber(f) => IEvNumber(f)
|
||||||
| FRValueDistOrNumber(FRValueNumber(n)) => IevNumber(n)
|
| FRValueDistOrNumber(FRValueNumber(n)) => IEvNumber(n)
|
||||||
| FRValueDistOrNumber(FRValueDist(n)) => IevDistribution(n)
|
| FRValueDistOrNumber(FRValueDist(n)) => IEvDistribution(n)
|
||||||
| FRValueDist(dist) => IevDistribution(dist)
|
| FRValueDist(dist) => IEvDistribution(dist)
|
||||||
| FRValueArray(elements) => IevArray(elements->E.A2.fmap(matchReverse))
|
| FRValueArray(elements) => IEvArray(elements->E.A2.fmap(matchReverse))
|
||||||
| FRValueRecord(frValueRecord) => {
|
| FRValueRecord(frValueRecord) => {
|
||||||
let map =
|
let map =
|
||||||
frValueRecord
|
frValueRecord
|
||||||
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
|
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
|
||||||
->Belt.Map.String.fromArray
|
->Belt.Map.String.fromArray
|
||||||
IevRecord(map)
|
IEvRecord(map)
|
||||||
}
|
}
|
||||||
| FRValueDict(frValueRecord) => {
|
| FRValueDict(frValueRecord) => {
|
||||||
let map =
|
let map =
|
||||||
|
@ -145,11 +145,11 @@ module FRType = {
|
||||||
->Js.Dict.entries
|
->Js.Dict.entries
|
||||||
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
|
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
|
||||||
->Belt.Map.String.fromArray
|
->Belt.Map.String.fromArray
|
||||||
IevRecord(map)
|
IEvRecord(map)
|
||||||
}
|
}
|
||||||
| FRValueLambda(l) => IevLambda(l)
|
| FRValueLambda(l) => IEvLambda(l)
|
||||||
| FRValueString(string) => IevString(string)
|
| FRValueString(string) => IEvString(string)
|
||||||
| FRValueVariant(string) => IevString(string)
|
| FRValueVariant(string) => IEvString(string)
|
||||||
| FRValueAny(f) => matchReverse(f)
|
| FRValueAny(f) => matchReverse(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ let impossibleError = "Wrong inputs / Logically impossible"
|
||||||
|
|
||||||
module Wrappers = {
|
module Wrappers = {
|
||||||
let symbolic = r => DistributionTypes.Symbolic(r)
|
let symbolic = r => DistributionTypes.Symbolic(r)
|
||||||
let evDistribution = r => ReducerInterface_InternalExpressionValue.IevDistribution(r)
|
let evDistribution = r => ReducerInterface_InternalExpressionValue.IEvDistribution(r)
|
||||||
let evNumber = r => ReducerInterface_InternalExpressionValue.IevNumber(r)
|
let evNumber = r => ReducerInterface_InternalExpressionValue.IEvNumber(r)
|
||||||
let evArray = r => ReducerInterface_InternalExpressionValue.IevArray(r)
|
let evArray = r => ReducerInterface_InternalExpressionValue.IEvArray(r)
|
||||||
let evRecord = r => ReducerInterface_InternalExpressionValue.IevRecord(r)
|
let evRecord = r => ReducerInterface_InternalExpressionValue.IEvRecord(r)
|
||||||
let evString = r => ReducerInterface_InternalExpressionValue.IevString(r)
|
let evString = r => ReducerInterface_InternalExpressionValue.IEvString(r)
|
||||||
let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution
|
let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Declaration = {
|
||||||
inputs
|
inputs
|
||||||
->E.A2.fmap(getMinMax)
|
->E.A2.fmap(getMinMax)
|
||||||
->E.A.R.firstErrorOrOpen
|
->E.A.R.firstErrorOrOpen
|
||||||
->E.R2.fmap(args => ReducerInterface_InternalExpressionValue.IevDeclaration(
|
->E.R2.fmap(args => ReducerInterface_InternalExpressionValue.IEvDeclaration(
|
||||||
Declaration.make(lambda, args),
|
Declaration.make(lambda, args),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
|
||||||
let expressionValue =
|
let expressionValue =
|
||||||
xyCoords
|
xyCoords
|
||||||
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
|
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
|
||||||
->E.R2.fmap(r => ReducerInterface_InternalExpressionValue.IevDistribution(
|
->E.R2.fmap(r => ReducerInterface_InternalExpressionValue.IEvDistribution(
|
||||||
PointSet(makeDist(r)),
|
PointSet(makeDist(r)),
|
||||||
))
|
))
|
||||||
expressionValue
|
expressionValue
|
||||||
|
|
|
@ -11,7 +11,7 @@ let getType = (nameSpace: t, id: string) => {
|
||||||
let NameSpace(container) = nameSpace
|
let NameSpace(container) = nameSpace
|
||||||
Belt.Map.String.get(container, typeAliasesKey)->Belt.Option.flatMap(aliases =>
|
Belt.Map.String.get(container, typeAliasesKey)->Belt.Option.flatMap(aliases =>
|
||||||
switch aliases {
|
switch aliases {
|
||||||
| IevRecord(r) => Belt.Map.String.get(r, id)
|
| IEvRecord(r) => Belt.Map.String.get(r, id)
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ let getTypeOf = (nameSpace: t, id: string) => {
|
||||||
let NameSpace(container) = nameSpace
|
let NameSpace(container) = nameSpace
|
||||||
Belt.Map.String.get(container, typeReferencesKey)->Belt.Option.flatMap(defs =>
|
Belt.Map.String.get(container, typeReferencesKey)->Belt.Option.flatMap(defs =>
|
||||||
switch defs {
|
switch defs {
|
||||||
| IevRecord(r) => Belt.Map.String.get(r, id)
|
| IEvRecord(r) => Belt.Map.String.get(r, id)
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -41,23 +41,23 @@ let emptyMap: map = Belt.Map.String.empty
|
||||||
|
|
||||||
let setTypeAlias = (nameSpace: t, id: string, value): t => {
|
let setTypeAlias = (nameSpace: t, id: string, value): t => {
|
||||||
let NameSpace(container) = nameSpace
|
let NameSpace(container) = nameSpace
|
||||||
let rValue = Belt.Map.String.getWithDefault(container, typeAliasesKey, IevRecord(emptyMap))
|
let rValue = Belt.Map.String.getWithDefault(container, typeAliasesKey, IEvRecord(emptyMap))
|
||||||
let r = switch rValue {
|
let r = switch rValue {
|
||||||
| IevRecord(r) => r
|
| IEvRecord(r) => r
|
||||||
| _ => emptyMap
|
| _ => emptyMap
|
||||||
}
|
}
|
||||||
let r2 = Belt.Map.String.set(r, id, value)->IevRecord
|
let r2 = Belt.Map.String.set(r, id, value)->IEvRecord
|
||||||
Belt.Map.String.set(container, typeAliasesKey, r2)->NameSpace
|
Belt.Map.String.set(container, typeAliasesKey, r2)->NameSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
let setTypeOf = (nameSpace: t, id: string, value): t => {
|
let setTypeOf = (nameSpace: t, id: string, value): t => {
|
||||||
let NameSpace(container) = nameSpace
|
let NameSpace(container) = nameSpace
|
||||||
let rValue = Belt.Map.String.getWithDefault(container, typeReferencesKey, IevRecord(emptyMap))
|
let rValue = Belt.Map.String.getWithDefault(container, typeReferencesKey, IEvRecord(emptyMap))
|
||||||
let r = switch rValue {
|
let r = switch rValue {
|
||||||
| IevRecord(r) => r
|
| IEvRecord(r) => r
|
||||||
| _ => emptyMap
|
| _ => emptyMap
|
||||||
}
|
}
|
||||||
let r2 = Belt.Map.String.set(r, id, value)->IevRecord
|
let r2 = Belt.Map.String.set(r, id, value)->IEvRecord
|
||||||
Belt.Map.String.set(container, typeReferencesKey, r2)->NameSpace
|
Belt.Map.String.set(container, typeReferencesKey, r2)->NameSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,10 @@ let emptyModule: t = NameSpace(Belt.Map.String.empty)
|
||||||
let fromTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceFromTypeScriptBindings
|
let fromTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceFromTypeScriptBindings
|
||||||
let toTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceToTypeScriptBindings
|
let toTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceToTypeScriptBindings
|
||||||
|
|
||||||
let toExpressionValue = (nameSpace: t): expressionValue => IevModule(nameSpace)
|
let toExpressionValue = (nameSpace: t): expressionValue => IEvModule(nameSpace)
|
||||||
let fromExpressionValue = (aValue: expressionValue): t =>
|
let fromExpressionValue = (aValue: expressionValue): t =>
|
||||||
switch aValue {
|
switch aValue {
|
||||||
| IevModule(nameSpace) => nameSpace
|
| IEvModule(nameSpace) => nameSpace
|
||||||
| _ => emptyModule
|
| _ => emptyModule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ let define = (nameSpace: t, identifier: string, ev: expressionValue): t => {
|
||||||
Belt.Map.String.set(container, identifier, ev)->NameSpace // TODO build lambda for polymorphic functions here
|
Belt.Map.String.set(container, identifier, ev)->NameSpace // TODO build lambda for polymorphic functions here
|
||||||
}
|
}
|
||||||
let defineNumber = (nameSpace: t, identifier: string, value: float): t =>
|
let defineNumber = (nameSpace: t, identifier: string, value: float): t =>
|
||||||
nameSpace->define(identifier, IevNumber(value))
|
nameSpace->define(identifier, IEvNumber(value))
|
||||||
|
|
||||||
let defineModule = (nameSpace: t, identifier: string, value: t): t =>
|
let defineModule = (nameSpace: t, identifier: string, value: t): t =>
|
||||||
nameSpace->define(identifier, toExpressionValue(value))
|
nameSpace->define(identifier, toExpressionValue(value))
|
||||||
|
|
|
@ -10,7 +10,7 @@ let isOfResolvedType = (aType, aValue) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch aType {
|
switch aType {
|
||||||
| IevTypeIdentifier(aTypeIdentifier) => caseTypeIdentifier(aTypeIdentifier, aValue)
|
| IEvTypeIdentifier(aTypeIdentifier) => caseTypeIdentifier(aTypeIdentifier, aValue)
|
||||||
| _ => false
|
| _ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,12 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
let constructRecord = arrayOfPairs => {
|
let constructRecord = arrayOfPairs => {
|
||||||
Belt.Array.map(arrayOfPairs, pairValue =>
|
Belt.Array.map(arrayOfPairs, pairValue =>
|
||||||
switch pairValue {
|
switch pairValue {
|
||||||
| IevArray([IevString(key), valueValue]) => (key, valueValue)
|
| IEvArray([IEvString(key), valueValue]) => (key, valueValue)
|
||||||
| _ => ("wrong key type", pairValue->toStringWithType->IevString)
|
| _ => ("wrong key type", pairValue->toStringWithType->IEvString)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->Belt.Map.String.fromArray
|
->Belt.Map.String.fromArray
|
||||||
->IevRecord
|
->IEvRecord
|
||||||
->Ok
|
->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
let doAddArray = (originalA, b) => {
|
let doAddArray = (originalA, b) => {
|
||||||
let a = originalA->Js.Array2.copy
|
let a = originalA->Js.Array2.copy
|
||||||
let _ = Js.Array2.pushMany(a, b)
|
let _ = Js.Array2.pushMany(a, b)
|
||||||
a->IevArray->Ok
|
a->IEvArray->Ok
|
||||||
}
|
}
|
||||||
let doAddString = (a, b) => {
|
let doAddString = (a, b) => {
|
||||||
let answer = Js.String2.concat(a, b)
|
let answer = Js.String2.concat(a, b)
|
||||||
answer->IevString->Ok
|
answer->IEvString->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
let inspect = (value: expressionValue) => {
|
let inspect = (value: expressionValue) => {
|
||||||
|
@ -80,14 +80,14 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
}
|
}
|
||||||
|
|
||||||
let doSetBindings = (bindings: nameSpace, symbol: string, value: expressionValue) => {
|
let doSetBindings = (bindings: nameSpace, symbol: string, value: expressionValue) => {
|
||||||
Module.set(bindings, symbol, value)->IevModule->Ok
|
Module.set(bindings, symbol, value)->IEvModule->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
let doSetTypeAliasBindings = (bindings: nameSpace, symbol: string, value: expressionValue) =>
|
let doSetTypeAliasBindings = (bindings: nameSpace, symbol: string, value: expressionValue) =>
|
||||||
Module.setTypeAlias(bindings, symbol, value)->IevModule->Ok
|
Module.setTypeAlias(bindings, symbol, value)->IEvModule->Ok
|
||||||
|
|
||||||
let doSetTypeOfBindings = (bindings: nameSpace, symbol: string, value: expressionValue) =>
|
let doSetTypeOfBindings = (bindings: nameSpace, symbol: string, value: expressionValue) =>
|
||||||
Module.setTypeOf(bindings, symbol, value)->IevModule->Ok
|
Module.setTypeOf(bindings, symbol, value)->IEvModule->Ok
|
||||||
|
|
||||||
let doExportBindings = (bindings: nameSpace) => bindings->Module.toExpressionValue->Ok
|
let doExportBindings = (bindings: nameSpace) => bindings->Module.toExpressionValue->Ok
|
||||||
|
|
||||||
|
@ -97,13 +97,13 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
let rNewElem = Lambda.doLambdaCall(aLambdaValue, list{elem}, environment, reducer)
|
let rNewElem = Lambda.doLambdaCall(aLambdaValue, list{elem}, environment, reducer)
|
||||||
rNewElem->Result.map(newElem =>
|
rNewElem->Result.map(newElem =>
|
||||||
switch newElem {
|
switch newElem {
|
||||||
| IevBool(true) => list{elem, ...acc}
|
| IEvBool(true) => list{elem, ...acc}
|
||||||
| _ => acc
|
| _ => acc
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IevArray)
|
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IEvArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
let doMapArray = (aValueArray, aLambdaValue) => {
|
let doMapArray = (aValueArray, aLambdaValue) => {
|
||||||
|
@ -113,36 +113,36 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
rNewElem->Result.map(newElem => list{newElem, ...acc})
|
rNewElem->Result.map(newElem => list{newElem, ...acc})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IevArray)
|
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IEvArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
module SampleMap = {
|
module SampleMap = {
|
||||||
type t = SampleSetDist.t
|
type t = SampleSetDist.t
|
||||||
let doLambdaCall = (aLambdaValue, list) =>
|
let doLambdaCall = (aLambdaValue, list) =>
|
||||||
switch Lambda.doLambdaCall(aLambdaValue, list, environment, reducer) {
|
switch Lambda.doLambdaCall(aLambdaValue, list, environment, reducer) {
|
||||||
| Ok(IevNumber(f)) => Ok(f)
|
| Ok(IEvNumber(f)) => Ok(f)
|
||||||
| _ => Error(Operation.SampleMapNeedsNtoNFunction)
|
| _ => Error(Operation.SampleMapNeedsNtoNFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
let toType = r =>
|
let toType = r =>
|
||||||
switch r {
|
switch r {
|
||||||
| Ok(r) => Ok(IevDistribution(SampleSet(r)))
|
| Ok(r) => Ok(IEvDistribution(SampleSet(r)))
|
||||||
| Error(r) => Error(REDistributionError(SampleSetError(r)))
|
| Error(r) => Error(REDistributionError(SampleSetError(r)))
|
||||||
}
|
}
|
||||||
|
|
||||||
let map1 = (sampleSetDist: t, aLambdaValue) => {
|
let map1 = (sampleSetDist: t, aLambdaValue) => {
|
||||||
let fn = r => doLambdaCall(aLambdaValue, list{IevNumber(r)})
|
let fn = r => doLambdaCall(aLambdaValue, list{IEvNumber(r)})
|
||||||
toType(SampleSetDist.samplesMap(~fn, sampleSetDist))
|
toType(SampleSetDist.samplesMap(~fn, sampleSetDist))
|
||||||
}
|
}
|
||||||
|
|
||||||
let map2 = (t1: t, t2: t, aLambdaValue) => {
|
let map2 = (t1: t, t2: t, aLambdaValue) => {
|
||||||
let fn = (a, b) => doLambdaCall(aLambdaValue, list{IevNumber(a), IevNumber(b)})
|
let fn = (a, b) => doLambdaCall(aLambdaValue, list{IEvNumber(a), IEvNumber(b)})
|
||||||
SampleSetDist.map2(~fn, ~t1, ~t2)->toType
|
SampleSetDist.map2(~fn, ~t1, ~t2)->toType
|
||||||
}
|
}
|
||||||
|
|
||||||
let map3 = (t1: t, t2: t, t3: t, aLambdaValue) => {
|
let map3 = (t1: t, t2: t, t3: t, aLambdaValue) => {
|
||||||
let fn = (a, b, c) =>
|
let fn = (a, b, c) =>
|
||||||
doLambdaCall(aLambdaValue, list{IevNumber(a), IevNumber(b), IevNumber(c)})
|
doLambdaCall(aLambdaValue, list{IEvNumber(a), IEvNumber(b), IEvNumber(c)})
|
||||||
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
|
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,127 +165,127 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
|
|
||||||
let typeModifier_memberOf = (aType, anArray) => {
|
let typeModifier_memberOf = (aType, anArray) => {
|
||||||
let newRecord = Belt.Map.String.fromArray([
|
let newRecord = Belt.Map.String.fromArray([
|
||||||
("typeTag", IevString("typeIdentifier")),
|
("typeTag", IEvString("typeIdentifier")),
|
||||||
("typeIdentifier", aType),
|
("typeIdentifier", aType),
|
||||||
])
|
])
|
||||||
newRecord->Belt.Map.String.set("memberOf", anArray)->IevRecord->Ok
|
newRecord->Belt.Map.String.set("memberOf", anArray)->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
let typeModifier_memberOf_update = (aRecord, anArray) => {
|
let typeModifier_memberOf_update = (aRecord, anArray) => {
|
||||||
aRecord->Belt.Map.String.set("memberOf", anArray)->IevRecord->Ok
|
aRecord->Belt.Map.String.set("memberOf", anArray)->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
let typeModifier_min = (aType, value) => {
|
let typeModifier_min = (aType, value) => {
|
||||||
let newRecord = Belt.Map.String.fromArray([
|
let newRecord = Belt.Map.String.fromArray([
|
||||||
("typeTag", IevString("typeIdentifier")),
|
("typeTag", IEvString("typeIdentifier")),
|
||||||
("typeIdentifier", aType),
|
("typeIdentifier", aType),
|
||||||
])
|
])
|
||||||
newRecord->Belt.Map.String.set("min", value)->IevRecord->Ok
|
newRecord->Belt.Map.String.set("min", value)->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
let typeModifier_min_update = (aRecord, value) => {
|
let typeModifier_min_update = (aRecord, value) => {
|
||||||
aRecord->Belt.Map.String.set("min", value)->IevRecord->Ok
|
aRecord->Belt.Map.String.set("min", value)->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
let typeModifier_max = (aType, value) => {
|
let typeModifier_max = (aType, value) => {
|
||||||
let newRecord = Belt.Map.String.fromArray([
|
let newRecord = Belt.Map.String.fromArray([
|
||||||
("typeTag", IevString("typeIdentifier")),
|
("typeTag", IEvString("typeIdentifier")),
|
||||||
("typeIdentifier", aType),
|
("typeIdentifier", aType),
|
||||||
])
|
])
|
||||||
newRecord->Belt.Map.String.set("max", value)->IevRecord->Ok
|
newRecord->Belt.Map.String.set("max", value)->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
let typeModifier_max_update = (aRecord, value) =>
|
let typeModifier_max_update = (aRecord, value) =>
|
||||||
aRecord->Belt.Map.String.set("max", value)->IevRecord->Ok
|
aRecord->Belt.Map.String.set("max", value)->IEvRecord->Ok
|
||||||
|
|
||||||
let typeModifier_opaque_update = aRecord =>
|
let typeModifier_opaque_update = aRecord =>
|
||||||
aRecord->Belt.Map.String.set("opaque", IevBool(true))->IevRecord->Ok
|
aRecord->Belt.Map.String.set("opaque", IEvBool(true))->IEvRecord->Ok
|
||||||
|
|
||||||
let typeOr = evArray => {
|
let typeOr = evArray => {
|
||||||
let newRecord = Belt.Map.String.fromArray([
|
let newRecord = Belt.Map.String.fromArray([
|
||||||
("typeTag", IevString("typeOr")),
|
("typeTag", IEvString("typeOr")),
|
||||||
("typeOr", evArray),
|
("typeOr", evArray),
|
||||||
])
|
])
|
||||||
newRecord->IevRecord->Ok
|
newRecord->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
let typeFunction = anArray => {
|
let typeFunction = anArray => {
|
||||||
let output = Belt.Array.getUnsafe(anArray, Js.Array2.length(anArray) - 1)
|
let output = Belt.Array.getUnsafe(anArray, Js.Array2.length(anArray) - 1)
|
||||||
let inputs = Js.Array2.slice(anArray, ~start=0, ~end_=-1)
|
let inputs = Js.Array2.slice(anArray, ~start=0, ~end_=-1)
|
||||||
let newRecord = Belt.Map.String.fromArray([
|
let newRecord = Belt.Map.String.fromArray([
|
||||||
("typeTag", IevString("typeFunction")),
|
("typeTag", IEvString("typeFunction")),
|
||||||
("inputs", IevArray(inputs)),
|
("inputs", IEvArray(inputs)),
|
||||||
("output", output),
|
("output", output),
|
||||||
])
|
])
|
||||||
newRecord->IevRecord->Ok
|
newRecord->IEvRecord->Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
switch call {
|
switch call {
|
||||||
| ("$_atIndex_$", [IevArray(aValueArray), IevNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
|
| ("$_atIndex_$", [IEvArray(aValueArray), IEvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
|
||||||
| ("$_atIndex_$", [IevModule(dict), IevString(sIndex)]) => moduleAtIndex(dict, sIndex)
|
| ("$_atIndex_$", [IEvModule(dict), IEvString(sIndex)]) => moduleAtIndex(dict, sIndex)
|
||||||
| ("$_atIndex_$", [IevRecord(dict), IevString(sIndex)]) => recordAtIndex(dict, sIndex)
|
| ("$_atIndex_$", [IEvRecord(dict), IEvString(sIndex)]) => recordAtIndex(dict, sIndex)
|
||||||
| ("$_constructArray_$", [IevArray(aValueArray)]) => IevArray(aValueArray)->Ok
|
| ("$_constructArray_$", [IEvArray(aValueArray)]) => IEvArray(aValueArray)->Ok
|
||||||
| ("$_constructRecord_$", [IevArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
|
| ("$_constructRecord_$", [IEvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
|
||||||
| ("$_exportBindings_$", [IevModule(nameSpace)]) => doExportBindings(nameSpace)
|
| ("$_exportBindings_$", [IEvModule(nameSpace)]) => doExportBindings(nameSpace)
|
||||||
| ("$_setBindings_$", [IevModule(nameSpace), IevSymbol(symbol), value]) =>
|
| ("$_setBindings_$", [IEvModule(nameSpace), IEvSymbol(symbol), value]) =>
|
||||||
doSetBindings(nameSpace, symbol, value)
|
doSetBindings(nameSpace, symbol, value)
|
||||||
| ("$_setTypeAliasBindings_$", [IevModule(nameSpace), IevTypeIdentifier(symbol), value]) =>
|
| ("$_setTypeAliasBindings_$", [IEvModule(nameSpace), IEvTypeIdentifier(symbol), value]) =>
|
||||||
doSetTypeAliasBindings(nameSpace, symbol, value)
|
doSetTypeAliasBindings(nameSpace, symbol, value)
|
||||||
| ("$_setTypeOfBindings_$", [IevModule(nameSpace), IevSymbol(symbol), value]) =>
|
| ("$_setTypeOfBindings_$", [IEvModule(nameSpace), IEvSymbol(symbol), value]) =>
|
||||||
doSetTypeOfBindings(nameSpace, symbol, value)
|
doSetTypeOfBindings(nameSpace, symbol, value)
|
||||||
| ("$_typeModifier_memberOf_$", [IevTypeIdentifier(typeIdentifier), IevArray(arr)]) =>
|
| ("$_typeModifier_memberOf_$", [IEvTypeIdentifier(typeIdentifier), IEvArray(arr)]) =>
|
||||||
typeModifier_memberOf(IevTypeIdentifier(typeIdentifier), IevArray(arr))
|
typeModifier_memberOf(IEvTypeIdentifier(typeIdentifier), IEvArray(arr))
|
||||||
| ("$_typeModifier_memberOf_$", [IevRecord(typeRecord), IevArray(arr)]) =>
|
| ("$_typeModifier_memberOf_$", [IEvRecord(typeRecord), IEvArray(arr)]) =>
|
||||||
typeModifier_memberOf_update(typeRecord, IevArray(arr))
|
typeModifier_memberOf_update(typeRecord, IEvArray(arr))
|
||||||
| ("$_typeModifier_min_$", [IevTypeIdentifier(typeIdentifier), value]) =>
|
| ("$_typeModifier_min_$", [IEvTypeIdentifier(typeIdentifier), value]) =>
|
||||||
typeModifier_min(IevTypeIdentifier(typeIdentifier), value)
|
typeModifier_min(IEvTypeIdentifier(typeIdentifier), value)
|
||||||
| ("$_typeModifier_min_$", [IevRecord(typeRecord), value]) =>
|
| ("$_typeModifier_min_$", [IEvRecord(typeRecord), value]) =>
|
||||||
typeModifier_min_update(typeRecord, value)
|
typeModifier_min_update(typeRecord, value)
|
||||||
| ("$_typeModifier_max_$", [IevTypeIdentifier(typeIdentifier), value]) =>
|
| ("$_typeModifier_max_$", [IEvTypeIdentifier(typeIdentifier), value]) =>
|
||||||
typeModifier_max(IevTypeIdentifier(typeIdentifier), value)
|
typeModifier_max(IEvTypeIdentifier(typeIdentifier), value)
|
||||||
| ("$_typeModifier_max_$", [IevRecord(typeRecord), value]) =>
|
| ("$_typeModifier_max_$", [IEvRecord(typeRecord), value]) =>
|
||||||
typeModifier_max_update(typeRecord, value)
|
typeModifier_max_update(typeRecord, value)
|
||||||
| ("$_typeModifier_opaque_$", [IevRecord(typeRecord)]) => typeModifier_opaque_update(typeRecord)
|
| ("$_typeModifier_opaque_$", [IEvRecord(typeRecord)]) => typeModifier_opaque_update(typeRecord)
|
||||||
| ("$_typeOr_$", [IevArray(arr)]) => typeOr(IevArray(arr))
|
| ("$_typeOr_$", [IEvArray(arr)]) => typeOr(IEvArray(arr))
|
||||||
| ("$_typeFunction_$", [IevArray(arr)]) => typeFunction(arr)
|
| ("$_typeFunction_$", [IEvArray(arr)]) => typeFunction(arr)
|
||||||
| ("concat", [IevArray(aValueArray), IevArray(bValueArray)]) =>
|
| ("concat", [IEvArray(aValueArray), IEvArray(bValueArray)]) =>
|
||||||
doAddArray(aValueArray, bValueArray)
|
doAddArray(aValueArray, bValueArray)
|
||||||
| ("concat", [IevString(aValueString), IevString(bValueString)]) =>
|
| ("concat", [IEvString(aValueString), IEvString(bValueString)]) =>
|
||||||
doAddString(aValueString, bValueString)
|
doAddString(aValueString, bValueString)
|
||||||
| ("inspect", [value, IevString(label)]) => inspectLabel(value, label)
|
| ("inspect", [value, IEvString(label)]) => inspectLabel(value, label)
|
||||||
| ("inspect", [value]) => inspect(value)
|
| ("inspect", [value]) => inspect(value)
|
||||||
| ("filter", [IevArray(aValueArray), IevLambda(aLambdaValue)]) =>
|
| ("filter", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
|
||||||
doKeepArray(aValueArray, aLambdaValue)
|
doKeepArray(aValueArray, aLambdaValue)
|
||||||
| ("map", [IevArray(aValueArray), IevLambda(aLambdaValue)]) =>
|
| ("map", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
|
||||||
doMapArray(aValueArray, aLambdaValue)
|
doMapArray(aValueArray, aLambdaValue)
|
||||||
| ("mapSamples", [IevDistribution(SampleSet(dist)), IevLambda(aLambdaValue)]) =>
|
| ("mapSamples", [IEvDistribution(SampleSet(dist)), IEvLambda(aLambdaValue)]) =>
|
||||||
SampleMap.map1(dist, aLambdaValue)
|
SampleMap.map1(dist, aLambdaValue)
|
||||||
| (
|
| (
|
||||||
"mapSamples2",
|
"mapSamples2",
|
||||||
[
|
[
|
||||||
IevDistribution(SampleSet(dist1)),
|
IEvDistribution(SampleSet(dist1)),
|
||||||
IevDistribution(SampleSet(dist2)),
|
IEvDistribution(SampleSet(dist2)),
|
||||||
IevLambda(aLambdaValue),
|
IEvLambda(aLambdaValue),
|
||||||
],
|
],
|
||||||
) =>
|
) =>
|
||||||
SampleMap.map2(dist1, dist2, aLambdaValue)
|
SampleMap.map2(dist1, dist2, aLambdaValue)
|
||||||
| (
|
| (
|
||||||
"mapSamples3",
|
"mapSamples3",
|
||||||
[
|
[
|
||||||
IevDistribution(SampleSet(dist1)),
|
IEvDistribution(SampleSet(dist1)),
|
||||||
IevDistribution(SampleSet(dist2)),
|
IEvDistribution(SampleSet(dist2)),
|
||||||
IevDistribution(SampleSet(dist3)),
|
IEvDistribution(SampleSet(dist3)),
|
||||||
IevLambda(aLambdaValue),
|
IEvLambda(aLambdaValue),
|
||||||
],
|
],
|
||||||
) =>
|
) =>
|
||||||
SampleMap.map3(dist1, dist2, dist3, aLambdaValue)
|
SampleMap.map3(dist1, dist2, dist3, aLambdaValue)
|
||||||
| ("reduce", [IevArray(aValueArray), initialValue, IevLambda(aLambdaValue)]) =>
|
| ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
||||||
doReduceArray(aValueArray, initialValue, aLambdaValue)
|
doReduceArray(aValueArray, initialValue, aLambdaValue)
|
||||||
| ("reduceReverse", [IevArray(aValueArray), initialValue, IevLambda(aLambdaValue)]) =>
|
| ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
||||||
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
|
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
|
||||||
| ("reverse", [IevArray(aValueArray)]) => aValueArray->Belt.Array.reverse->IevArray->Ok
|
| ("reverse", [IEvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->IEvArray->Ok
|
||||||
| (_, [IevBool(_)])
|
| (_, [IEvBool(_)])
|
||||||
| (_, [IevNumber(_)])
|
| (_, [IEvNumber(_)])
|
||||||
| (_, [IevString(_)])
|
| (_, [IEvString(_)])
|
||||||
| (_, [IevBool(_), IevBool(_)])
|
| (_, [IEvBool(_), IEvBool(_)])
|
||||||
| (_, [IevNumber(_), IevNumber(_)])
|
| (_, [IEvNumber(_), IEvNumber(_)])
|
||||||
| (_, [IevString(_), IevString(_)]) =>
|
| (_, [IEvString(_), IEvString(_)]) =>
|
||||||
callMathJs(call)
|
callMathJs(call)
|
||||||
| call =>
|
| call =>
|
||||||
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error
|
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error
|
||||||
|
|
|
@ -52,7 +52,7 @@ let dispatchMacroCall = (
|
||||||
let doBindStatement = (bindingExpr: expression, statement: expression, environment) => {
|
let doBindStatement = (bindingExpr: expression, statement: expression, environment) => {
|
||||||
let defaultStatement = ErrorValue.REAssignmentExpected->Error
|
let defaultStatement = ErrorValue.REAssignmentExpected->Error
|
||||||
switch statement {
|
switch statement {
|
||||||
| ExpressionT.EList(list{ExpressionT.EValue(IevCall(callName)), symbolExpr, statement}) => {
|
| ExpressionT.EList(list{ExpressionT.EValue(IEvCall(callName)), symbolExpr, statement}) => {
|
||||||
let setBindingsFn = correspondingSetBindingsFn(callName)
|
let setBindingsFn = correspondingSetBindingsFn(callName)
|
||||||
if setBindingsFn !== "" {
|
if setBindingsFn !== "" {
|
||||||
useExpressionToSetBindings(bindingExpr, environment, statement, (
|
useExpressionToSetBindings(bindingExpr, environment, statement, (
|
||||||
|
@ -78,7 +78,7 @@ let dispatchMacroCall = (
|
||||||
) => boundStatement)
|
) => boundStatement)
|
||||||
|
|
||||||
switch statement {
|
switch statement {
|
||||||
| ExpressionT.EList(list{ExpressionT.EValue(IevCall(callName)), symbolExpr, statement}) => {
|
| ExpressionT.EList(list{ExpressionT.EValue(IEvCall(callName)), symbolExpr, statement}) => {
|
||||||
let setBindingsFn = correspondingSetBindingsFn(callName)
|
let setBindingsFn = correspondingSetBindingsFn(callName)
|
||||||
if setBindingsFn !== "" {
|
if setBindingsFn !== "" {
|
||||||
useExpressionToSetBindings(bindingExpr, environment, statement, (
|
useExpressionToSetBindings(bindingExpr, environment, statement, (
|
||||||
|
@ -137,11 +137,11 @@ let dispatchMacroCall = (
|
||||||
let rCondition = reduceExpression(blockCondition, bindings, environment)
|
let rCondition = reduceExpression(blockCondition, bindings, environment)
|
||||||
rCondition->Result.flatMap(conditionValue =>
|
rCondition->Result.flatMap(conditionValue =>
|
||||||
switch conditionValue {
|
switch conditionValue {
|
||||||
| ExpressionValue.IevBool(false) => {
|
| ExpressionValue.IEvBool(false) => {
|
||||||
let ifFalseBlock = eBlock(list{ifFalse})
|
let ifFalseBlock = eBlock(list{ifFalse})
|
||||||
ExpressionWithContext.withContext(ifFalseBlock, bindings)->Ok
|
ExpressionWithContext.withContext(ifFalseBlock, bindings)->Ok
|
||||||
}
|
}
|
||||||
| ExpressionValue.IevBool(true) => {
|
| ExpressionValue.IEvBool(true) => {
|
||||||
let ifTrueBlock = eBlock(list{ifTrue})
|
let ifTrueBlock = eBlock(list{ifTrue})
|
||||||
ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok
|
ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok
|
||||||
}
|
}
|
||||||
|
@ -156,32 +156,32 @@ let dispatchMacroCall = (
|
||||||
> =>
|
> =>
|
||||||
switch aList {
|
switch aList {
|
||||||
| list{
|
| list{
|
||||||
ExpressionT.EValue(IevCall("$$_bindStatement_$$")),
|
ExpressionT.EValue(IEvCall("$$_bindStatement_$$")),
|
||||||
bindingExpr: ExpressionT.expression,
|
bindingExpr: ExpressionT.expression,
|
||||||
statement,
|
statement,
|
||||||
} =>
|
} =>
|
||||||
doBindStatement(bindingExpr, statement, environment)
|
doBindStatement(bindingExpr, statement, environment)
|
||||||
| list{ExpressionT.EValue(IevCall("$$_bindStatement_$$")), statement} =>
|
| list{ExpressionT.EValue(IEvCall("$$_bindStatement_$$")), statement} =>
|
||||||
// bindings of the context are used when there is no binding expression
|
// bindings of the context are used when there is no binding expression
|
||||||
doBindStatement(eModule(bindings), statement, environment)
|
doBindStatement(eModule(bindings), statement, environment)
|
||||||
| list{
|
| list{
|
||||||
ExpressionT.EValue(IevCall("$$_bindExpression_$$")),
|
ExpressionT.EValue(IEvCall("$$_bindExpression_$$")),
|
||||||
bindingExpr: ExpressionT.expression,
|
bindingExpr: ExpressionT.expression,
|
||||||
expression,
|
expression,
|
||||||
} =>
|
} =>
|
||||||
doBindExpression(bindingExpr, expression, environment)
|
doBindExpression(bindingExpr, expression, environment)
|
||||||
| list{ExpressionT.EValue(IevCall("$$_bindExpression_$$")), expression} =>
|
| list{ExpressionT.EValue(IEvCall("$$_bindExpression_$$")), expression} =>
|
||||||
// bindings of the context are used when there is no binding expression
|
// bindings of the context are used when there is no binding expression
|
||||||
doBindExpression(eModule(bindings), expression, environment)
|
doBindExpression(eModule(bindings), expression, environment)
|
||||||
| list{ExpressionT.EValue(IevCall("$$_block_$$")), ...exprs} =>
|
| list{ExpressionT.EValue(IEvCall("$$_block_$$")), ...exprs} =>
|
||||||
doBlock(exprs, bindings, environment)
|
doBlock(exprs, bindings, environment)
|
||||||
| list{
|
| list{
|
||||||
ExpressionT.EValue(IevCall("$$_lambda_$$")),
|
ExpressionT.EValue(IEvCall("$$_lambda_$$")),
|
||||||
ExpressionT.EValue(IevArrayString(parameters)),
|
ExpressionT.EValue(IEvArrayString(parameters)),
|
||||||
lambdaDefinition,
|
lambdaDefinition,
|
||||||
} =>
|
} =>
|
||||||
doLambdaDefinition(bindings, parameters, lambdaDefinition)
|
doLambdaDefinition(bindings, parameters, lambdaDefinition)
|
||||||
| list{ExpressionT.EValue(IevCall("$$_ternary_$$")), condition, ifTrue, ifFalse} =>
|
| list{ExpressionT.EValue(IEvCall("$$_ternary_$$")), condition, ifTrue, ifFalse} =>
|
||||||
doTernary(condition, ifTrue, ifFalse, bindings, environment)
|
doTernary(condition, ifTrue, ifFalse, bindings, environment)
|
||||||
| _ => ExpressionWithContext.noContext(ExpressionT.EList(aList))->Ok
|
| _ => ExpressionWithContext.noContext(ExpressionT.EList(aList))->Ok
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ let rec reduceExpression = (expression: t, bindings: T.bindings, environment: en
|
||||||
| T.EValue(value) => value->Ok
|
| T.EValue(value) => value->Ok
|
||||||
| T.EList(list) =>
|
| T.EList(list) =>
|
||||||
switch list {
|
switch list {
|
||||||
| list{EValue(IevCall(fName)), ..._args} =>
|
| list{EValue(IEvCall(fName)), ..._args} =>
|
||||||
switch Macro.isMacroName(fName) {
|
switch Macro.isMacroName(fName) {
|
||||||
// A macro expands then reduces itself
|
// A macro expands then reduces itself
|
||||||
| true => Macro.doMacroCall(expression, bindings, environment, reduceExpression)
|
| true => Macro.doMacroCall(expression, bindings, environment, reduceExpression)
|
||||||
|
@ -75,7 +75,7 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
|
||||||
'e,
|
'e,
|
||||||
> =>
|
> =>
|
||||||
switch valueList {
|
switch valueList {
|
||||||
| list{IevCall(fName), ...args} => {
|
| list{IEvCall(fName), ...args} => {
|
||||||
let rCheckedArgs = switch fName {
|
let rCheckedArgs = switch fName {
|
||||||
| "$_setBindings_$" | "$_setTypeOfBindings_$" | "$_setTypeAliasBindings_$" => args->Ok
|
| "$_setBindings_$" | "$_setTypeOfBindings_$" | "$_setTypeAliasBindings_$" => args->Ok
|
||||||
| _ => args->Lambda.checkIfReduced
|
| _ => args->Lambda.checkIfReduced
|
||||||
|
@ -85,14 +85,14 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
|
||||||
(fName, checkedArgs->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
|
(fName, checkedArgs->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
| list{IevLambda(_)} =>
|
| list{IEvLambda(_)} =>
|
||||||
// TODO: remove on solving issue#558
|
// TODO: remove on solving issue#558
|
||||||
valueList
|
valueList
|
||||||
->Lambda.checkIfReduced
|
->Lambda.checkIfReduced
|
||||||
->Result.flatMap(reducedValueList =>
|
->Result.flatMap(reducedValueList =>
|
||||||
reducedValueList->Belt.List.toArray->InternalExpressionValue.IevArray->Ok
|
reducedValueList->Belt.List.toArray->InternalExpressionValue.IEvArray->Ok
|
||||||
)
|
)
|
||||||
| list{IevLambda(lamdaCall), ...args} =>
|
| list{IEvLambda(lamdaCall), ...args} =>
|
||||||
args
|
args
|
||||||
->Lambda.checkIfReduced
|
->Lambda.checkIfReduced
|
||||||
->Result.flatMap(checkedArgs =>
|
->Result.flatMap(checkedArgs =>
|
||||||
|
@ -103,7 +103,7 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
|
||||||
valueList
|
valueList
|
||||||
->Lambda.checkIfReduced
|
->Lambda.checkIfReduced
|
||||||
->Result.flatMap(reducedValueList =>
|
->Result.flatMap(reducedValueList =>
|
||||||
reducedValueList->Belt.List.toArray->InternalExpressionValue.IevArray->Ok
|
reducedValueList->Belt.List.toArray->InternalExpressionValue.IEvArray->Ok
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ let evaluateUsingOptions = (
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Ievaluates Squiggle code and bindings via Reducer and answers the result
|
IEvaluates Squiggle code and bindings via Reducer and answers the result
|
||||||
*/
|
*/
|
||||||
let evaluate = (code: string): result<externalExpressionValue, errorValue> => {
|
let evaluate = (code: string): result<externalExpressionValue, errorValue> => {
|
||||||
evaluateUsingOptions(~environment=None, ~externalBindings=None, code)
|
evaluateUsingOptions(~environment=None, ~externalBindings=None, code)
|
||||||
|
|
|
@ -21,7 +21,7 @@ let rec replaceSymbols = (bindings: ExpressionT.bindings, expression: expression
|
||||||
replaceSymbolOnValue(bindings, value)->Result.map(evValue => evValue->ExpressionT.EValue)
|
replaceSymbolOnValue(bindings, value)->Result.map(evValue => evValue->ExpressionT.EValue)
|
||||||
| ExpressionT.EList(list) =>
|
| ExpressionT.EList(list) =>
|
||||||
switch list {
|
switch list {
|
||||||
| list{EValue(IevCall(fName)), ..._args} =>
|
| list{EValue(IEvCall(fName)), ..._args} =>
|
||||||
switch isMacroName(fName) {
|
switch isMacroName(fName) {
|
||||||
// A macro reduces itself so we dont dive in it
|
// A macro reduces itself so we dont dive in it
|
||||||
| true => expression->Ok
|
| true => expression->Ok
|
||||||
|
@ -43,12 +43,12 @@ and replaceSymbolsOnExpressionList = (bindings, list) => {
|
||||||
}
|
}
|
||||||
and replaceSymbolOnValue = (bindings, evValue: expressionValue) =>
|
and replaceSymbolOnValue = (bindings, evValue: expressionValue) =>
|
||||||
switch evValue {
|
switch evValue {
|
||||||
| IevSymbol(symbol) => Module.getWithDefault(bindings, symbol, evValue)->Ok
|
| IEvSymbol(symbol) => Module.getWithDefault(bindings, symbol, evValue)->Ok
|
||||||
| IevCall(symbol) => Module.getWithDefault(bindings, symbol, evValue)->checkIfCallable
|
| IEvCall(symbol) => Module.getWithDefault(bindings, symbol, evValue)->checkIfCallable
|
||||||
| _ => evValue->Ok
|
| _ => evValue->Ok
|
||||||
}
|
}
|
||||||
and checkIfCallable = (evValue: expressionValue) =>
|
and checkIfCallable = (evValue: expressionValue) =>
|
||||||
switch evValue {
|
switch evValue {
|
||||||
| IevCall(_) | IevLambda(_) => evValue->Ok
|
| IEvCall(_) | IEvLambda(_) => evValue->Ok
|
||||||
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
|
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,16 @@ type internalCode = ReducerInterface_InternalExpressionValue.internalCode
|
||||||
|
|
||||||
external castExpressionToInternalCode: expressionOrFFI => internalCode = "%identity"
|
external castExpressionToInternalCode: expressionOrFFI => internalCode = "%identity"
|
||||||
|
|
||||||
let eArray = anArray => anArray->BExpressionValue.IevArray->BExpressionT.EValue
|
let eArray = anArray => anArray->BExpressionValue.IEvArray->BExpressionT.EValue
|
||||||
|
|
||||||
let eArrayString = anArray => anArray->BExpressionValue.IevArrayString->BExpressionT.EValue
|
let eArrayString = anArray => anArray->BExpressionValue.IEvArrayString->BExpressionT.EValue
|
||||||
|
|
||||||
let eBindings = (anArray: array<(string, BExpressionValue.expressionValue)>) =>
|
let eBindings = (anArray: array<(string, BExpressionValue.expressionValue)>) =>
|
||||||
anArray->BModule.fromArray->BModule.toExpressionValue->BExpressionT.EValue
|
anArray->BModule.fromArray->BModule.toExpressionValue->BExpressionT.EValue
|
||||||
|
|
||||||
let eBool = aBool => aBool->BExpressionValue.IevBool->BExpressionT.EValue
|
let eBool = aBool => aBool->BExpressionValue.IEvBool->BExpressionT.EValue
|
||||||
|
|
||||||
let eCall = (name: string): expression => name->BExpressionValue.IevCall->BExpressionT.EValue
|
let eCall = (name: string): expression => name->BExpressionValue.IEvCall->BExpressionT.EValue
|
||||||
|
|
||||||
let eFunction = (fName: string, lispArgs: list<expression>): expression => {
|
let eFunction = (fName: string, lispArgs: list<expression>): expression => {
|
||||||
let fn = fName->eCall
|
let fn = fName->eCall
|
||||||
|
@ -33,7 +33,7 @@ let eLambda = (
|
||||||
context: BExpressionValue.nameSpace,
|
context: BExpressionValue.nameSpace,
|
||||||
expr: expression,
|
expr: expression,
|
||||||
) => {
|
) => {
|
||||||
BExpressionValue.IevLambda({
|
BExpressionValue.IEvLambda({
|
||||||
parameters: parameters,
|
parameters: parameters,
|
||||||
context: context,
|
context: context,
|
||||||
body: NotFFI(expr)->castExpressionToInternalCode,
|
body: NotFFI(expr)->castExpressionToInternalCode,
|
||||||
|
@ -42,27 +42,27 @@ let eLambda = (
|
||||||
|
|
||||||
let eLambdaFFI = (parameters: array<string>, ffiFn: ffiFn) => {
|
let eLambdaFFI = (parameters: array<string>, ffiFn: ffiFn) => {
|
||||||
let context = BModule.emptyModule
|
let context = BModule.emptyModule
|
||||||
BExpressionValue.IevLambda({
|
BExpressionValue.IEvLambda({
|
||||||
parameters: parameters,
|
parameters: parameters,
|
||||||
context: context,
|
context: context,
|
||||||
body: FFI(ffiFn)->castExpressionToInternalCode,
|
body: FFI(ffiFn)->castExpressionToInternalCode,
|
||||||
})->BExpressionT.EValue
|
})->BExpressionT.EValue
|
||||||
}
|
}
|
||||||
|
|
||||||
let eNumber = aNumber => aNumber->BExpressionValue.IevNumber->BExpressionT.EValue
|
let eNumber = aNumber => aNumber->BExpressionValue.IEvNumber->BExpressionT.EValue
|
||||||
|
|
||||||
let eRecord = aMap => aMap->BExpressionValue.IevRecord->BExpressionT.EValue
|
let eRecord = aMap => aMap->BExpressionValue.IEvRecord->BExpressionT.EValue
|
||||||
|
|
||||||
let eString = aString => aString->BExpressionValue.IevString->BExpressionT.EValue
|
let eString = aString => aString->BExpressionValue.IEvString->BExpressionT.EValue
|
||||||
|
|
||||||
let eSymbol = (name: string): expression => name->BExpressionValue.IevSymbol->BExpressionT.EValue
|
let eSymbol = (name: string): expression => name->BExpressionValue.IEvSymbol->BExpressionT.EValue
|
||||||
|
|
||||||
let eList = (list: list<expression>): expression => list->BExpressionT.EList
|
let eList = (list: list<expression>): expression => list->BExpressionT.EList
|
||||||
|
|
||||||
let eBlock = (exprs: list<expression>): expression => eFunction("$$_block_$$", exprs)
|
let eBlock = (exprs: list<expression>): expression => eFunction("$$_block_$$", exprs)
|
||||||
|
|
||||||
let eModule = (nameSpace: BExpressionValue.nameSpace): expression =>
|
let eModule = (nameSpace: BExpressionValue.nameSpace): expression =>
|
||||||
nameSpace->BExpressionValue.IevModule->BExpressionT.EValue
|
nameSpace->BExpressionValue.IEvModule->BExpressionT.EValue
|
||||||
|
|
||||||
let eLetStatement = (symbol: string, valueExpression: expression): expression =>
|
let eLetStatement = (symbol: string, valueExpression: expression): expression =>
|
||||||
eFunction("$_let_$", list{eSymbol(symbol), valueExpression})
|
eFunction("$_let_$", list{eSymbol(symbol), valueExpression})
|
||||||
|
@ -80,7 +80,7 @@ let eBindExpressionDefault = (expression: expression): expression =>
|
||||||
eFunction("$$_bindExpression_$$", list{expression})
|
eFunction("$$_bindExpression_$$", list{expression})
|
||||||
|
|
||||||
let eIdentifier = (name: string): expression =>
|
let eIdentifier = (name: string): expression =>
|
||||||
name->BExpressionValue.IevSymbol->BExpressionT.EValue
|
name->BExpressionValue.IEvSymbol->BExpressionT.EValue
|
||||||
|
|
||||||
let eTypeIdentifier = (name: string): expression =>
|
let eTypeIdentifier = (name: string): expression =>
|
||||||
name->BExpressionValue.IevTypeIdentifier->BExpressionT.EValue
|
name->BExpressionValue.IEvTypeIdentifier->BExpressionT.EValue
|
||||||
|
|
|
@ -29,7 +29,7 @@ let checkIfReduced = (args: list<expressionValue>) =>
|
||||||
args->Belt.List.reduceReverse(Ok(list{}), (rAcc, arg) =>
|
args->Belt.List.reduceReverse(Ok(list{}), (rAcc, arg) =>
|
||||||
rAcc->Result.flatMap(acc =>
|
rAcc->Result.flatMap(acc =>
|
||||||
switch arg {
|
switch arg {
|
||||||
| IevSymbol(symbol) => ErrorValue.RESymbolNotFound(symbol)->Error
|
| IEvSymbol(symbol) => ErrorValue.RESymbolNotFound(symbol)->Error
|
||||||
| _ => list{arg, ...acc}->Ok
|
| _ => list{arg, ...acc}->Ok
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,7 +28,7 @@ type reducerFn = (
|
||||||
*/
|
*/
|
||||||
let rec toString = expression =>
|
let rec toString = expression =>
|
||||||
switch expression {
|
switch expression {
|
||||||
| EList(list{EValue(IevCall("$$_block_$$")), ...statements}) =>
|
| EList(list{EValue(IEvCall("$$_block_$$")), ...statements}) =>
|
||||||
`{${Belt.List.map(statements, aValue => toString(aValue))
|
`{${Belt.List.map(statements, aValue => toString(aValue))
|
||||||
->Extra.List.interperse("; ")
|
->Extra.List.interperse("; ")
|
||||||
->Belt.List.toArray
|
->Belt.List.toArray
|
||||||
|
|
|
@ -8,10 +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 jsToIev = (jsValue): result<expressionValue, errorValue> =>
|
let jsToIEv = (jsValue): result<expressionValue, errorValue> =>
|
||||||
switch Js.typeof(jsValue) {
|
switch Js.typeof(jsValue) {
|
||||||
| "boolean" => jsValue->castBool->IevBool->Ok
|
| "boolean" => jsValue->castBool->IEvBool->Ok
|
||||||
| "number" => jsValue->castNumber->IevNumber->Ok
|
| "number" => jsValue->castNumber->IEvNumber->Ok
|
||||||
| "string" => jsValue->castString->IevString->Ok
|
| "string" => jsValue->castString->IEvString->Ok
|
||||||
| other => RETodo(`Unhandled MathJs literal type: ${Js.String.make(other)}`)->Error
|
| other => RETodo(`Unhandled MathJs literal type: ${Js.String.make(other)}`)->Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ let eval__: string => 'a = %raw(`function (expr) { return {value: Mathjs.evaluat
|
||||||
let eval = (expr: string): result<expressionValue, errorValue> => {
|
let eval = (expr: string): result<expressionValue, errorValue> => {
|
||||||
try {
|
try {
|
||||||
let answer = eval__(expr)
|
let answer = eval__(expr)
|
||||||
answer["value"]->JavaScript.Gate.jsToIev
|
answer["value"]->JavaScript.Gate.jsToIEv
|
||||||
} catch {
|
} catch {
|
||||||
| Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error
|
| Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,23 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
|
||||||
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
|
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
|
||||||
> => {
|
> => {
|
||||||
switch call {
|
switch call {
|
||||||
| ("toString", [IevDate(t)]) => EV.IevString(DateTime.Date.toString(t))->Ok->Some
|
| ("toString", [IEvDate(t)]) => EV.IEvString(DateTime.Date.toString(t))->Ok->Some
|
||||||
| ("makeDateFromYear", [IevNumber(year)]) =>
|
| ("makeDateFromYear", [IEvNumber(year)]) =>
|
||||||
switch DateTime.Date.makeFromYear(year) {
|
switch DateTime.Date.makeFromYear(year) {
|
||||||
| Ok(t) => EV.IevDate(t)->Ok->Some
|
| Ok(t) => EV.IEvDate(t)->Ok->Some
|
||||||
| Error(e) => Reducer_ErrorValue.RETodo(e)->Error->Some
|
| Error(e) => Reducer_ErrorValue.RETodo(e)->Error->Some
|
||||||
}
|
}
|
||||||
| ("dateFromNumber", [IevNumber(f)]) => EV.IevDate(DateTime.Date.fromFloat(f))->Ok->Some
|
| ("dateFromNumber", [IEvNumber(f)]) => EV.IEvDate(DateTime.Date.fromFloat(f))->Ok->Some
|
||||||
| ("toNumber", [IevDate(f)]) => EV.IevNumber(DateTime.Date.toFloat(f))->Ok->Some
|
| ("toNumber", [IEvDate(f)]) => EV.IEvNumber(DateTime.Date.toFloat(f))->Ok->Some
|
||||||
| ("subtract", [IevDate(d1), IevDate(d2)]) =>
|
| ("subtract", [IEvDate(d1), IEvDate(d2)]) =>
|
||||||
switch DateTime.Date.subtract(d1, d2) {
|
switch DateTime.Date.subtract(d1, d2) {
|
||||||
| Ok(d) => EV.IevTimeDuration(d)->Ok
|
| Ok(d) => EV.IEvTimeDuration(d)->Ok
|
||||||
| Error(e) => Error(RETodo(e))
|
| Error(e) => Error(RETodo(e))
|
||||||
}->Some
|
}->Some
|
||||||
| ("subtract", [IevDate(d1), IevTimeDuration(d2)]) =>
|
| ("subtract", [IEvDate(d1), IEvTimeDuration(d2)]) =>
|
||||||
EV.IevDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some
|
EV.IEvDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some
|
||||||
| ("add", [IevDate(d1), IevTimeDuration(d2)]) =>
|
| ("add", [IEvDate(d1), IEvTimeDuration(d2)]) =>
|
||||||
EV.IevDate(DateTime.Date.addDuration(d1, d2))->Ok->Some
|
EV.IEvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,31 +5,31 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
|
||||||
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
|
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
|
||||||
> => {
|
> => {
|
||||||
switch call {
|
switch call {
|
||||||
| ("toString", [IevTimeDuration(t)]) => EV.IevString(DateTime.Duration.toString(t))->Ok->Some
|
| ("toString", [IEvTimeDuration(t)]) => EV.IEvString(DateTime.Duration.toString(t))->Ok->Some
|
||||||
| ("minutes", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
|
| ("minutes", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
|
||||||
| ("fromUnit_minutes", [IevNumber(f)]) =>
|
| ("fromUnit_minutes", [IEvNumber(f)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
|
||||||
| ("hours", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
|
| ("hours", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
|
||||||
| ("fromUnit_hours", [IevNumber(f)]) =>
|
| ("fromUnit_hours", [IEvNumber(f)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
|
||||||
| ("days", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
|
| ("days", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
|
||||||
| ("fromUnit_days", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
|
| ("fromUnit_days", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
|
||||||
| ("years", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
|
| ("years", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
|
||||||
| ("fromUnit_years", [IevNumber(f)]) =>
|
| ("fromUnit_years", [IEvNumber(f)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
|
||||||
| ("toHours", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toHours(f))->Ok->Some
|
| ("toHours", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toHours(f))->Ok->Some
|
||||||
| ("toMinutes", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toMinutes(f))->Ok->Some
|
| ("toMinutes", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toMinutes(f))->Ok->Some
|
||||||
| ("toDays", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toDays(f))->Ok->Some
|
| ("toDays", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toDays(f))->Ok->Some
|
||||||
| ("toYears", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toYears(f))->Ok->Some
|
| ("toYears", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toYears(f))->Ok->Some
|
||||||
| ("add", [IevTimeDuration(d1), IevTimeDuration(d2)]) =>
|
| ("add", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some
|
||||||
| ("subtract", [IevTimeDuration(d1), IevTimeDuration(d2)]) =>
|
| ("subtract", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some
|
||||||
| ("multiply", [IevTimeDuration(d1), IevNumber(d2)]) =>
|
| ("multiply", [IEvTimeDuration(d1), IEvNumber(d2)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some
|
||||||
| ("divide", [IevTimeDuration(d1), IevNumber(d2)]) =>
|
| ("divide", [IEvTimeDuration(d1), IEvNumber(d2)]) =>
|
||||||
EV.IevTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
|
EV.IEvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
|
||||||
| ("divide", [IevTimeDuration(d1), IevTimeDuration(d2)]) => EV.IevNumber(d1 /. d2)->Ok->Some
|
| ("divide", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) => EV.IEvNumber(d1 /. d2)->Ok->Some
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ module Helpers = {
|
||||||
DistributionTypes.genericDist,
|
DistributionTypes.genericDist,
|
||||||
)> =>
|
)> =>
|
||||||
switch args {
|
switch args {
|
||||||
| [IevDistribution(a), IevDistribution(b)] => Some((a, b))
|
| [IEvDistribution(a), IEvDistribution(b)] => Some((a, b))
|
||||||
| [IevNumber(a), IevDistribution(b)] => Some((GenericDist.fromFloat(a), b))
|
| [IEvNumber(a), IEvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
|
||||||
| [IevDistribution(a), IevNumber(b)] => Some((a, GenericDist.fromFloat(b)))
|
| [IEvDistribution(a), IEvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ module Helpers = {
|
||||||
|
|
||||||
let parseNumber = (args: expressionValue): Belt.Result.t<float, string> =>
|
let parseNumber = (args: expressionValue): Belt.Result.t<float, string> =>
|
||||||
switch args {
|
switch args {
|
||||||
| IevNumber(x) => Ok(x)
|
| IEvNumber(x) => Ok(x)
|
||||||
| _ => Error("Not a number")
|
| _ => Error("Not a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,8 @@ module Helpers = {
|
||||||
|
|
||||||
let parseDist = (args: expressionValue): Belt.Result.t<DistributionTypes.genericDist, string> =>
|
let parseDist = (args: expressionValue): Belt.Result.t<DistributionTypes.genericDist, string> =>
|
||||||
switch args {
|
switch args {
|
||||||
| IevDistribution(x) => Ok(x)
|
| IEvDistribution(x) => Ok(x)
|
||||||
| IevNumber(x) => Ok(GenericDist.fromFloat(x))
|
| IEvNumber(x) => Ok(GenericDist.fromFloat(x))
|
||||||
| _ => Error("Not a distribution")
|
| _ => Error("Not a distribution")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,12 +128,12 @@ module Helpers = {
|
||||||
let error = (err: string): DistributionOperation.outputType =>
|
let error = (err: string): DistributionOperation.outputType =>
|
||||||
err->DistributionTypes.ArgumentError->GenDistError
|
err->DistributionTypes.ArgumentError->GenDistError
|
||||||
switch args {
|
switch args {
|
||||||
| [IevArray(distributions)] =>
|
| [IEvArray(distributions)] =>
|
||||||
switch parseDistributionArray(distributions) {
|
switch parseDistributionArray(distributions) {
|
||||||
| Ok(distrs) => mixtureWithDefaultWeights(distrs, ~env)
|
| Ok(distrs) => mixtureWithDefaultWeights(distrs, ~env)
|
||||||
| Error(err) => error(err)
|
| Error(err) => error(err)
|
||||||
}
|
}
|
||||||
| [IevArray(distributions), IevArray(weights)] =>
|
| [IEvArray(distributions), IEvArray(weights)] =>
|
||||||
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
|
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
|
||||||
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts, ~env)
|
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts, ~env)
|
||||||
| (Error(err), Ok(_)) => error(err)
|
| (Error(err), Ok(_)) => error(err)
|
||||||
|
@ -142,7 +142,7 @@ module Helpers = {
|
||||||
}
|
}
|
||||||
| _ =>
|
| _ =>
|
||||||
switch E.A.last(args) {
|
switch E.A.last(args) {
|
||||||
| Some(IevArray(b)) => {
|
| Some(IEvArray(b)) => {
|
||||||
let weights = parseNumberArray(b)
|
let weights = parseNumberArray(b)
|
||||||
let distributions = parseDistributionArray(
|
let distributions = parseDistributionArray(
|
||||||
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
|
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
|
||||||
|
@ -152,8 +152,8 @@ module Helpers = {
|
||||||
| Error(err) => error(err)
|
| Error(err) => error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| Some(IevNumber(_))
|
| Some(IEvNumber(_))
|
||||||
| Some(IevDistribution(_)) =>
|
| Some(IEvDistribution(_)) =>
|
||||||
switch parseDistributionArray(args) {
|
switch parseDistributionArray(args) {
|
||||||
| Ok(distributions) => mixtureWithDefaultWeights(distributions, ~env)
|
| Ok(distributions) => mixtureWithDefaultWeights(distributions, ~env)
|
||||||
| Error(err) => error(err)
|
| Error(err) => error(err)
|
||||||
|
@ -200,14 +200,14 @@ let dispatchToGenericOutput = (
|
||||||
): option<DistributionOperation.outputType> => {
|
): option<DistributionOperation.outputType> => {
|
||||||
let (fnName, args) = call
|
let (fnName, args) = call
|
||||||
switch (fnName, args) {
|
switch (fnName, args) {
|
||||||
| ("triangular" as fnName, [IevNumber(f1), IevNumber(f2), IevNumber(f3)]) =>
|
| ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) =>
|
||||||
SymbolicConstructors.threeFloat(fnName)
|
SymbolicConstructors.threeFloat(fnName)
|
||||||
->E.R.bind(r => r(f1, f2, f3))
|
->E.R.bind(r => r(f1, f2, f3))
|
||||||
->SymbolicConstructors.symbolicResultToOutput
|
->SymbolicConstructors.symbolicResultToOutput
|
||||||
| ("sample", [IevDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env)
|
| ("sample", [IEvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env)
|
||||||
| ("sampleN", [IevDistribution(dist), IevNumber(n)]) =>
|
| ("sampleN", [IEvDistribution(dist), IEvNumber(n)]) =>
|
||||||
Some(FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n))))
|
Some(FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n))))
|
||||||
| (("mean" | "stdev" | "variance" | "min" | "max" | "mode") as op, [IevDistribution(dist)]) => {
|
| (("mean" | "stdev" | "variance" | "min" | "max" | "mode") as op, [IEvDistribution(dist)]) => {
|
||||||
let fn = switch op {
|
let fn = switch op {
|
||||||
| "mean" => #Mean
|
| "mean" => #Mean
|
||||||
| "stdev" => #Stdev
|
| "stdev" => #Stdev
|
||||||
|
@ -219,13 +219,13 @@ let dispatchToGenericOutput = (
|
||||||
}
|
}
|
||||||
Helpers.toFloatFn(fn, dist, ~env)
|
Helpers.toFloatFn(fn, dist, ~env)
|
||||||
}
|
}
|
||||||
| ("integralSum", [IevDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
|
| ("integralSum", [IEvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
|
||||||
| ("toString", [IevDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
|
| ("toString", [IEvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
|
||||||
| ("sparkline", [IevDistribution(dist)]) =>
|
| ("sparkline", [IEvDistribution(dist)]) =>
|
||||||
Helpers.toStringFn(ToSparkline(MagicNumbers.Environment.sparklineLength), dist, ~env)
|
Helpers.toStringFn(ToSparkline(MagicNumbers.Environment.sparklineLength), dist, ~env)
|
||||||
| ("sparkline", [IevDistribution(dist), IevNumber(n)]) =>
|
| ("sparkline", [IEvDistribution(dist), IEvNumber(n)]) =>
|
||||||
Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist, ~env)
|
Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist, ~env)
|
||||||
| ("exp", [IevDistribution(a)]) =>
|
| ("exp", [IEvDistribution(a)]) =>
|
||||||
// https://mathjs.org/docs/reference/functions/exp.html
|
// https://mathjs.org/docs/reference/functions/exp.html
|
||||||
Helpers.twoDiststoDistFn(
|
Helpers.twoDiststoDistFn(
|
||||||
Algebraic(AsDefault),
|
Algebraic(AsDefault),
|
||||||
|
@ -234,62 +234,62 @@ let dispatchToGenericOutput = (
|
||||||
a,
|
a,
|
||||||
~env,
|
~env,
|
||||||
)->Some
|
)->Some
|
||||||
| ("normalize", [IevDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
| ("normalize", [IEvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
||||||
| ("klDivergence", [IevDistribution(prediction), IevDistribution(answer)]) =>
|
| ("klDivergence", [IEvDistribution(prediction), IEvDistribution(answer)]) =>
|
||||||
Some(DistributionOperation.run(FromDist(ToScore(KLDivergence(answer)), prediction), ~env))
|
Some(DistributionOperation.run(FromDist(ToScore(KLDivergence(answer)), prediction), ~env))
|
||||||
| (
|
| (
|
||||||
"klDivergence",
|
"klDivergence",
|
||||||
[IevDistribution(prediction), IevDistribution(answer), IevDistribution(prior)],
|
[IEvDistribution(prediction), IEvDistribution(answer), IEvDistribution(prior)],
|
||||||
) =>
|
) =>
|
||||||
Helpers.klDivergenceWithPrior(prediction, answer, prior, env)
|
Helpers.klDivergenceWithPrior(prediction, answer, prior, env)
|
||||||
| (
|
| (
|
||||||
"logScoreWithPointAnswer",
|
"logScoreWithPointAnswer",
|
||||||
[IevDistribution(prediction), IevNumber(answer), IevDistribution(prior)],
|
[IEvDistribution(prediction), IEvNumber(answer), IEvDistribution(prior)],
|
||||||
)
|
)
|
||||||
| (
|
| (
|
||||||
"logScoreWithPointAnswer",
|
"logScoreWithPointAnswer",
|
||||||
[
|
[
|
||||||
IevDistribution(prediction),
|
IEvDistribution(prediction),
|
||||||
IevDistribution(Symbolic(#Float(answer))),
|
IEvDistribution(Symbolic(#Float(answer))),
|
||||||
IevDistribution(prior),
|
IEvDistribution(prior),
|
||||||
],
|
],
|
||||||
) =>
|
) =>
|
||||||
DistributionOperation.run(
|
DistributionOperation.run(
|
||||||
FromDist(ToScore(LogScore(answer, prior->Some)), prediction),
|
FromDist(ToScore(LogScore(answer, prior->Some)), prediction),
|
||||||
~env,
|
~env,
|
||||||
)->Some
|
)->Some
|
||||||
| ("logScoreWithPointAnswer", [IevDistribution(prediction), IevNumber(answer)])
|
| ("logScoreWithPointAnswer", [IEvDistribution(prediction), IEvNumber(answer)])
|
||||||
| (
|
| (
|
||||||
"logScoreWithPointAnswer",
|
"logScoreWithPointAnswer",
|
||||||
[IevDistribution(prediction), IevDistribution(Symbolic(#Float(answer)))],
|
[IEvDistribution(prediction), IEvDistribution(Symbolic(#Float(answer)))],
|
||||||
) =>
|
) =>
|
||||||
DistributionOperation.run(FromDist(ToScore(LogScore(answer, None)), prediction), ~env)->Some
|
DistributionOperation.run(FromDist(ToScore(LogScore(answer, None)), prediction), ~env)->Some
|
||||||
| ("isNormalized", [IevDistribution(dist)]) => Helpers.toBoolFn(IsNormalized, dist, ~env)
|
| ("isNormalized", [IEvDistribution(dist)]) => Helpers.toBoolFn(IsNormalized, dist, ~env)
|
||||||
| ("toPointSet", [IevDistribution(dist)]) => Helpers.toDistFn(ToPointSet, dist, ~env)
|
| ("toPointSet", [IEvDistribution(dist)]) => Helpers.toDistFn(ToPointSet, dist, ~env)
|
||||||
| ("scaleLog", [IevDistribution(dist)]) =>
|
| ("scaleLog", [IEvDistribution(dist)]) =>
|
||||||
Helpers.toDistFn(Scale(#Logarithm, MagicNumbers.Math.e), dist, ~env)
|
Helpers.toDistFn(Scale(#Logarithm, MagicNumbers.Math.e), dist, ~env)
|
||||||
| ("scaleLog10", [IevDistribution(dist)]) => Helpers.toDistFn(Scale(#Logarithm, 10.0), dist, ~env)
|
| ("scaleLog10", [IEvDistribution(dist)]) => Helpers.toDistFn(Scale(#Logarithm, 10.0), dist, ~env)
|
||||||
| ("scaleLog", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("scaleLog", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(Scale(#Logarithm, float), dist, ~env)
|
Helpers.toDistFn(Scale(#Logarithm, float), dist, ~env)
|
||||||
| ("scaleLogWithThreshold", [IevDistribution(dist), IevNumber(base), IevNumber(eps)]) =>
|
| ("scaleLogWithThreshold", [IEvDistribution(dist), IEvNumber(base), IEvNumber(eps)]) =>
|
||||||
Helpers.toDistFn(Scale(#LogarithmWithThreshold(eps), base), dist, ~env)
|
Helpers.toDistFn(Scale(#LogarithmWithThreshold(eps), base), dist, ~env)
|
||||||
| ("scaleMultiply", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("scaleMultiply", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(Scale(#Multiply, float), dist, ~env)
|
Helpers.toDistFn(Scale(#Multiply, float), dist, ~env)
|
||||||
| ("scalePow", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("scalePow", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(Scale(#Power, float), dist, ~env)
|
Helpers.toDistFn(Scale(#Power, float), dist, ~env)
|
||||||
| ("scaleExp", [IevDistribution(dist)]) =>
|
| ("scaleExp", [IEvDistribution(dist)]) =>
|
||||||
Helpers.toDistFn(Scale(#Power, MagicNumbers.Math.e), dist, ~env)
|
Helpers.toDistFn(Scale(#Power, MagicNumbers.Math.e), dist, ~env)
|
||||||
| ("cdf", [IevDistribution(dist), IevNumber(float)]) => Helpers.toFloatFn(#Cdf(float), dist, ~env)
|
| ("cdf", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Cdf(float), dist, ~env)
|
||||||
| ("pdf", [IevDistribution(dist), IevNumber(float)]) => Helpers.toFloatFn(#Pdf(float), dist, ~env)
|
| ("pdf", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Pdf(float), dist, ~env)
|
||||||
| ("inv", [IevDistribution(dist), IevNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
| ("inv", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||||
| ("quantile", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("quantile", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toFloatFn(#Inv(float), dist, ~env)
|
Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||||
| ("toSampleSet", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("toSampleSet", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
|
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
|
||||||
| ("toSampleSet", [IevDistribution(dist)]) =>
|
| ("toSampleSet", [IEvDistribution(dist)]) =>
|
||||||
Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env)
|
Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env)
|
||||||
| ("toList", [IevDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
|
| ("toList", [IEvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
|
||||||
| ("fromSamples", [IevArray(inputArray)]) => {
|
| ("fromSamples", [IEvArray(inputArray)]) => {
|
||||||
let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x)
|
let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x)
|
||||||
let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors)
|
let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors)
|
||||||
switch parsedArray {
|
switch parsedArray {
|
||||||
|
@ -297,15 +297,15 @@ let dispatchToGenericOutput = (
|
||||||
| Error(e) => GenDistError(SampleSetError(e))
|
| Error(e) => GenDistError(SampleSetError(e))
|
||||||
}->Some
|
}->Some
|
||||||
}
|
}
|
||||||
| ("inspect", [IevDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
|
| ("inspect", [IEvDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
|
||||||
| ("truncateLeft", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("truncateLeft", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(Truncate(Some(float), None), dist, ~env)
|
Helpers.toDistFn(Truncate(Some(float), None), dist, ~env)
|
||||||
| ("truncateRight", [IevDistribution(dist), IevNumber(float)]) =>
|
| ("truncateRight", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||||
Helpers.toDistFn(Truncate(None, Some(float)), dist, ~env)
|
Helpers.toDistFn(Truncate(None, Some(float)), dist, ~env)
|
||||||
| ("truncate", [IevDistribution(dist), IevNumber(float1), IevNumber(float2)]) =>
|
| ("truncate", [IEvDistribution(dist), IEvNumber(float1), IEvNumber(float2)]) =>
|
||||||
Helpers.toDistFn(Truncate(Some(float1), Some(float2)), dist, ~env)
|
Helpers.toDistFn(Truncate(Some(float1), Some(float2)), dist, ~env)
|
||||||
| ("mx" | "mixture", args) => Helpers.mixture(args, ~env)->Some
|
| ("mx" | "mixture", args) => Helpers.mixture(args, ~env)->Some
|
||||||
| ("log", [IevDistribution(a)]) =>
|
| ("log", [IEvDistribution(a)]) =>
|
||||||
Helpers.twoDiststoDistFn(
|
Helpers.twoDiststoDistFn(
|
||||||
Algebraic(AsDefault),
|
Algebraic(AsDefault),
|
||||||
"log",
|
"log",
|
||||||
|
@ -313,7 +313,7 @@ let dispatchToGenericOutput = (
|
||||||
GenericDist.fromFloat(MagicNumbers.Math.e),
|
GenericDist.fromFloat(MagicNumbers.Math.e),
|
||||||
~env,
|
~env,
|
||||||
)->Some
|
)->Some
|
||||||
| ("log10", [IevDistribution(a)]) =>
|
| ("log10", [IEvDistribution(a)]) =>
|
||||||
Helpers.twoDiststoDistFn(
|
Helpers.twoDiststoDistFn(
|
||||||
Algebraic(AsDefault),
|
Algebraic(AsDefault),
|
||||||
"log",
|
"log",
|
||||||
|
@ -321,7 +321,7 @@ let dispatchToGenericOutput = (
|
||||||
GenericDist.fromFloat(10.0),
|
GenericDist.fromFloat(10.0),
|
||||||
~env,
|
~env,
|
||||||
)->Some
|
)->Some
|
||||||
| ("unaryMinus", [IevDistribution(a)]) =>
|
| ("unaryMinus", [IEvDistribution(a)]) =>
|
||||||
Helpers.twoDiststoDistFn(
|
Helpers.twoDiststoDistFn(
|
||||||
Algebraic(AsDefault),
|
Algebraic(AsDefault),
|
||||||
"multiply",
|
"multiply",
|
||||||
|
@ -344,7 +344,7 @@ let dispatchToGenericOutput = (
|
||||||
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
||||||
Helpers.twoDiststoDistFn(Pointwise, arithmetic, fst, snd, ~env)
|
Helpers.twoDiststoDistFn(Pointwise, arithmetic, fst, snd, ~env)
|
||||||
)
|
)
|
||||||
| ("dotExp", [IevDistribution(a)]) =>
|
| ("dotExp", [IEvDistribution(a)]) =>
|
||||||
Helpers.twoDiststoDistFn(
|
Helpers.twoDiststoDistFn(
|
||||||
Pointwise,
|
Pointwise,
|
||||||
"dotPow",
|
"dotPow",
|
||||||
|
@ -361,12 +361,12 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
|
||||||
Reducer_ErrorValue.errorValue,
|
Reducer_ErrorValue.errorValue,
|
||||||
> =>
|
> =>
|
||||||
switch o {
|
switch o {
|
||||||
| Dist(d) => Ok(ReducerInterface_InternalExpressionValue.IevDistribution(d))
|
| Dist(d) => Ok(ReducerInterface_InternalExpressionValue.IEvDistribution(d))
|
||||||
| Float(d) => Ok(IevNumber(d))
|
| Float(d) => Ok(IEvNumber(d))
|
||||||
| String(d) => Ok(IevString(d))
|
| String(d) => Ok(IEvString(d))
|
||||||
| Bool(d) => Ok(IevBool(d))
|
| Bool(d) => Ok(IEvBool(d))
|
||||||
| FloatArray(d) =>
|
| FloatArray(d) =>
|
||||||
Ok(IevArray(d |> E.A.fmap(r => ReducerInterface_InternalExpressionValue.IevNumber(r))))
|
Ok(IEvArray(d |> E.A.fmap(r => ReducerInterface_InternalExpressionValue.IEvNumber(r))))
|
||||||
| GenDistError(err) => Error(REDistributionError(err))
|
| GenDistError(err) => Error(REDistributionError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,21 +7,21 @@ type environment = ExternalExpressionValue.environment
|
||||||
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
|
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
|
||||||
|
|
||||||
type rec expressionValue =
|
type rec expressionValue =
|
||||||
| IevArray(array<expressionValue>) // FIXME: Convert
|
| IEvArray(array<expressionValue>) // FIXME: Convert
|
||||||
| IevArrayString(array<string>) // FIXME: Convert
|
| IEvArrayString(array<string>) // FIXME: Convert
|
||||||
| IevBool(bool)
|
| IEvBool(bool)
|
||||||
| IevCall(string) // External function call
|
| IEvCall(string) // External function call
|
||||||
| IevDate(Js.Date.t)
|
| IEvDate(Js.Date.t)
|
||||||
| IevDeclaration(lambdaDeclaration)
|
| IEvDeclaration(lambdaDeclaration)
|
||||||
| IevDistribution(DistributionTypes.genericDist)
|
| IEvDistribution(DistributionTypes.genericDist)
|
||||||
| IevLambda(lambdaValue)
|
| IEvLambda(lambdaValue)
|
||||||
| IevModule(nameSpace) // FIXME: Convert
|
| IEvModule(nameSpace) // FIXME: Convert
|
||||||
| IevNumber(float)
|
| IEvNumber(float)
|
||||||
| IevRecord(map)
|
| IEvRecord(map)
|
||||||
| IevString(string)
|
| IEvString(string)
|
||||||
| IevSymbol(string)
|
| IEvSymbol(string)
|
||||||
| IevTimeDuration(float)
|
| IEvTimeDuration(float)
|
||||||
| IevTypeIdentifier(string)
|
| IEvTypeIdentifier(string)
|
||||||
and map = Belt.Map.String.t<expressionValue>
|
and map = Belt.Map.String.t<expressionValue>
|
||||||
and nameSpace = NameSpace(Belt.Map.String.t<expressionValue>)
|
and nameSpace = NameSpace(Belt.Map.String.t<expressionValue>)
|
||||||
and tmpExternalBindings = Js.Dict.t<expressionValue> // FIXME: Remove
|
and tmpExternalBindings = Js.Dict.t<expressionValue> // FIXME: Remove
|
||||||
|
@ -38,27 +38,27 @@ type functionCall = (string, array<expressionValue>)
|
||||||
|
|
||||||
let rec toString = aValue =>
|
let rec toString = aValue =>
|
||||||
switch aValue {
|
switch aValue {
|
||||||
| IevArray(anArray) => {
|
| IEvArray(anArray) => {
|
||||||
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
|
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
|
||||||
`[${args}]`
|
`[${args}]`
|
||||||
}
|
}
|
||||||
| IevArrayString(anArray) => {
|
| IEvArrayString(anArray) => {
|
||||||
let args = anArray->Js.Array2.toString
|
let args = anArray->Js.Array2.toString
|
||||||
`[${args}]`
|
`[${args}]`
|
||||||
}
|
}
|
||||||
| IevBool(aBool) => Js.String.make(aBool)
|
| IEvBool(aBool) => Js.String.make(aBool)
|
||||||
| IevCall(fName) => `:${fName}`
|
| IEvCall(fName) => `:${fName}`
|
||||||
| IevDate(date) => DateTime.Date.toString(date)
|
| IEvDate(date) => DateTime.Date.toString(date)
|
||||||
| IevDeclaration(d) => Declaration.toString(d, r => toString(IevLambda(r)))
|
| IEvDeclaration(d) => Declaration.toString(d, r => toString(IEvLambda(r)))
|
||||||
| IevDistribution(dist) => GenericDist.toString(dist)
|
| IEvDistribution(dist) => GenericDist.toString(dist)
|
||||||
| IevLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
|
| IEvLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
|
||||||
| IevModule(m) => `@${m->toStringNameSpace}`
|
| IEvModule(m) => `@${m->toStringNameSpace}`
|
||||||
| IevNumber(aNumber) => Js.String.make(aNumber)
|
| IEvNumber(aNumber) => Js.String.make(aNumber)
|
||||||
| IevRecord(aMap) => aMap->toStringMap
|
| IEvRecord(aMap) => aMap->toStringMap
|
||||||
| IevString(aString) => `'${aString}'`
|
| IEvString(aString) => `'${aString}'`
|
||||||
| IevSymbol(aString) => `:${aString}`
|
| IEvSymbol(aString) => `:${aString}`
|
||||||
| IevTimeDuration(t) => DateTime.Duration.toString(t)
|
| IEvTimeDuration(t) => DateTime.Duration.toString(t)
|
||||||
| IevTypeIdentifier(id) => `#${id}`
|
| IEvTypeIdentifier(id) => `#${id}`
|
||||||
}
|
}
|
||||||
and toStringMap = aMap => {
|
and toStringMap = aMap => {
|
||||||
let pairs =
|
let pairs =
|
||||||
|
@ -75,21 +75,21 @@ and toStringNameSpace = nameSpace => {
|
||||||
|
|
||||||
let toStringWithType = aValue =>
|
let toStringWithType = aValue =>
|
||||||
switch aValue {
|
switch aValue {
|
||||||
| IevArray(_) => `Array::${toString(aValue)}`
|
| IEvArray(_) => `Array::${toString(aValue)}`
|
||||||
| IevArrayString(_) => `ArrayString::${toString(aValue)}`
|
| IEvArrayString(_) => `ArrayString::${toString(aValue)}`
|
||||||
| IevBool(_) => `Bool::${toString(aValue)}`
|
| IEvBool(_) => `Bool::${toString(aValue)}`
|
||||||
| IevCall(_) => `Call::${toString(aValue)}`
|
| IEvCall(_) => `Call::${toString(aValue)}`
|
||||||
| IevDistribution(_) => `Distribution::${toString(aValue)}`
|
| IEvDistribution(_) => `Distribution::${toString(aValue)}`
|
||||||
| IevLambda(_) => `Lambda::${toString(aValue)}`
|
| IEvLambda(_) => `Lambda::${toString(aValue)}`
|
||||||
| IevNumber(_) => `Number::${toString(aValue)}`
|
| IEvNumber(_) => `Number::${toString(aValue)}`
|
||||||
| IevRecord(_) => `Record::${toString(aValue)}`
|
| IEvRecord(_) => `Record::${toString(aValue)}`
|
||||||
| IevString(_) => `String::${toString(aValue)}`
|
| IEvString(_) => `String::${toString(aValue)}`
|
||||||
| IevSymbol(_) => `Symbol::${toString(aValue)}`
|
| IEvSymbol(_) => `Symbol::${toString(aValue)}`
|
||||||
| IevDate(_) => `Date::${toString(aValue)}`
|
| IEvDate(_) => `Date::${toString(aValue)}`
|
||||||
| IevTimeDuration(_) => `Date::${toString(aValue)}`
|
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
|
||||||
| IevDeclaration(_) => `Declaration::${toString(aValue)}`
|
| IEvDeclaration(_) => `Declaration::${toString(aValue)}`
|
||||||
| IevTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
||||||
| IevModule(_) => `Module::${toString(aValue)}`
|
| IEvModule(_) => `Module::${toString(aValue)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let argsToString = (args: array<expressionValue>): string => {
|
let argsToString = (args: array<expressionValue>): string => {
|
||||||
|
@ -139,21 +139,21 @@ type functionDefinitionSignature =
|
||||||
|
|
||||||
let valueToValueType = value =>
|
let valueToValueType = value =>
|
||||||
switch value {
|
switch value {
|
||||||
| IevArray(_) => EvtArray
|
| IEvArray(_) => EvtArray
|
||||||
| IevArrayString(_) => EvtArrayString
|
| IEvArrayString(_) => EvtArrayString
|
||||||
| IevBool(_) => EvtBool
|
| IEvBool(_) => EvtBool
|
||||||
| IevCall(_) => EvtCall
|
| IEvCall(_) => EvtCall
|
||||||
| IevDistribution(_) => EvtDistribution
|
| IEvDistribution(_) => EvtDistribution
|
||||||
| IevLambda(_) => EvtLambda
|
| IEvLambda(_) => EvtLambda
|
||||||
| IevNumber(_) => EvtNumber
|
| IEvNumber(_) => EvtNumber
|
||||||
| IevRecord(_) => EvtRecord
|
| IEvRecord(_) => EvtRecord
|
||||||
| IevString(_) => EvtString
|
| IEvString(_) => EvtString
|
||||||
| IevSymbol(_) => EvtSymbol
|
| IEvSymbol(_) => EvtSymbol
|
||||||
| IevDate(_) => EvtDate
|
| IEvDate(_) => EvtDate
|
||||||
| IevTimeDuration(_) => EvtTimeDuration
|
| IEvTimeDuration(_) => EvtTimeDuration
|
||||||
| IevDeclaration(_) => EvtDeclaration
|
| IEvDeclaration(_) => EvtDeclaration
|
||||||
| IevTypeIdentifier(_) => EvtTypeIdentifier
|
| IEvTypeIdentifier(_) => EvtTypeIdentifier
|
||||||
| IevModule(_) => EvtModule
|
| IEvModule(_) => EvtModule
|
||||||
}
|
}
|
||||||
|
|
||||||
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
|
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
|
||||||
|
@ -187,25 +187,25 @@ let functionCallSignatureToString = (functionCallSignature: functionCallSignatur
|
||||||
|
|
||||||
let rec toExternal = (iev: expressionValue): ExternalExpressionValue.expressionValue => {
|
let rec toExternal = (iev: expressionValue): ExternalExpressionValue.expressionValue => {
|
||||||
switch iev {
|
switch iev {
|
||||||
| IevArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray
|
| IEvArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray
|
||||||
| IevArrayString(v) => EvArrayString(v)
|
| IEvArrayString(v) => EvArrayString(v)
|
||||||
| IevBool(v) => EvBool(v)
|
| IEvBool(v) => EvBool(v)
|
||||||
| IevCall(v) => EvCall(v)
|
| IEvCall(v) => EvCall(v)
|
||||||
| IevDistribution(v) => EvDistribution(v)
|
| IEvDistribution(v) => EvDistribution(v)
|
||||||
| IevLambda(v) => EvLambda(lambdaValueToExternal(v))
|
| IEvLambda(v) => EvLambda(lambdaValueToExternal(v))
|
||||||
| IevNumber(v) => EvNumber(v)
|
| IEvNumber(v) => EvNumber(v)
|
||||||
| IevRecord(v) => v->mapToExternal->EvRecord
|
| IEvRecord(v) => v->mapToExternal->EvRecord
|
||||||
| IevString(v) => EvString(v)
|
| IEvString(v) => EvString(v)
|
||||||
| IevSymbol(v) => EvSymbol(v)
|
| IEvSymbol(v) => EvSymbol(v)
|
||||||
| IevDate(v) => EvDate(v)
|
| IEvDate(v) => EvDate(v)
|
||||||
| IevTimeDuration(v) => EvTimeDuration(v)
|
| IEvTimeDuration(v) => EvTimeDuration(v)
|
||||||
| IevDeclaration(v) => {
|
| IEvDeclaration(v) => {
|
||||||
let fn = lambdaValueToExternal(v.fn)
|
let fn = lambdaValueToExternal(v.fn)
|
||||||
let args = v.args
|
let args = v.args
|
||||||
EvDeclaration({fn: fn, args: args})
|
EvDeclaration({fn: fn, args: args})
|
||||||
}
|
}
|
||||||
| IevTypeIdentifier(v) => EvTypeIdentifier(v)
|
| IEvTypeIdentifier(v) => EvTypeIdentifier(v)
|
||||||
| IevModule(v) => v->nameSpaceToTypeScriptBindings->EvModule
|
| IEvModule(v) => v->nameSpaceToTypeScriptBindings->EvModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
and mapToExternal = v =>
|
and mapToExternal = v =>
|
||||||
|
@ -225,25 +225,25 @@ and nameSpaceToTypeScriptBindings = (
|
||||||
|
|
||||||
let rec toInternal = (ev: ExternalExpressionValue.expressionValue): expressionValue => {
|
let rec toInternal = (ev: ExternalExpressionValue.expressionValue): expressionValue => {
|
||||||
switch ev {
|
switch ev {
|
||||||
| EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IevArray
|
| EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IEvArray
|
||||||
| EvArrayString(v) => IevArrayString(v)
|
| EvArrayString(v) => IEvArrayString(v)
|
||||||
| EvBool(v) => IevBool(v)
|
| EvBool(v) => IEvBool(v)
|
||||||
| EvCall(v) => IevCall(v)
|
| EvCall(v) => IEvCall(v)
|
||||||
| EvDistribution(v) => IevDistribution(v)
|
| EvDistribution(v) => IEvDistribution(v)
|
||||||
| EvLambda(v) => IevLambda(lambdaValueToInternal(v))
|
| EvLambda(v) => IEvLambda(lambdaValueToInternal(v))
|
||||||
| EvNumber(v) => IevNumber(v)
|
| EvNumber(v) => IEvNumber(v)
|
||||||
| EvRecord(v) => v->recordToInternal->IevRecord
|
| EvRecord(v) => v->recordToInternal->IEvRecord
|
||||||
| EvString(v) => IevString(v)
|
| EvString(v) => IEvString(v)
|
||||||
| EvSymbol(v) => IevSymbol(v)
|
| EvSymbol(v) => IEvSymbol(v)
|
||||||
| EvDate(v) => IevDate(v)
|
| EvDate(v) => IEvDate(v)
|
||||||
| EvTimeDuration(v) => IevTimeDuration(v)
|
| EvTimeDuration(v) => IEvTimeDuration(v)
|
||||||
| EvDeclaration(v) => {
|
| EvDeclaration(v) => {
|
||||||
let fn = lambdaValueToInternal(v.fn)
|
let fn = lambdaValueToInternal(v.fn)
|
||||||
let args = v.args
|
let args = v.args
|
||||||
IevDeclaration({fn: fn, args: args})
|
IEvDeclaration({fn: fn, args: args})
|
||||||
}
|
}
|
||||||
| EvTypeIdentifier(v) => IevTypeIdentifier(v)
|
| EvTypeIdentifier(v) => IEvTypeIdentifier(v)
|
||||||
| EvModule(v) => v->nameSpaceFromTypeScriptBindings->IevModule
|
| EvModule(v) => v->nameSpaceFromTypeScriptBindings->IEvModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
and recordToInternal = v =>
|
and recordToInternal = v =>
|
||||||
|
|
|
@ -37,9 +37,9 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
|
||||||
| "fromUnit_G"
|
| "fromUnit_G"
|
||||||
| "fromUnit_T"
|
| "fromUnit_T"
|
||||||
| "fromUnit_P") as op,
|
| "fromUnit_P") as op,
|
||||||
[IevNumber(f)],
|
[IEvNumber(f)],
|
||||||
) =>
|
) =>
|
||||||
op->ScientificUnit.getMultiplier->E.O2.fmap(multiplier => EV.IevNumber(f *. multiplier)->Ok)
|
op->ScientificUnit.getMultiplier->E.O2.fmap(multiplier => EV.IEvNumber(f *. multiplier)->Ok)
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ let availableNumbers: array<(string, float)> = [
|
||||||
|
|
||||||
let mathBindings: Bindings.t =
|
let mathBindings: Bindings.t =
|
||||||
availableNumbers
|
availableNumbers
|
||||||
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IevNumber(v)))
|
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IEvNumber(v)))
|
||||||
->Bindings.fromArray
|
->Bindings.fromArray
|
||||||
|
|
||||||
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
|
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user