Iev -> IEv Just more readable prefix

This commit is contained in:
Umur Ozkul 2022-06-23 20:38:07 +02:00
parent 24a9c52789
commit 07d5c6d8b3
23 changed files with 369 additions and 369 deletions

View File

@ -26,14 +26,14 @@ describe("bindStatement", () => {
// Now let's feed a binding to see what happens
testMacro(
[],
eBindStatement(eBindings([("x", IevNumber(2.))]), exampleStatementX),
eBindStatement(eBindings([("x", IEvNumber(2.))]), exampleStatementX),
"Ok((:$_setBindings_$ @{x: 2} :y 2) context: @{x: 2})",
)
// An expression does not return a binding, thus error
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
testMacro(
[("z", IevNumber(99.))],
[("z", IEvNumber(99.))],
eBindStatementDefault(exampleStatementY),
"Ok((:$_setBindings_$ @{z: 99} :y 1) context: @{z: 99})",
)
@ -43,24 +43,24 @@ describe("bindExpression", () => {
// x is simply bound in the expression
testMacro(
[],
eBindExpression(eBindings([("x", IevNumber(2.))]), eSymbol("x")),
eBindExpression(eBindings([("x", IEvNumber(2.))]), eSymbol("x")),
"Ok(2 context: @{x: 2})",
)
// When an let statement is the end expression then bindings are returned
testMacro(
[],
eBindExpression(eBindings([("x", IevNumber(2.))]), exampleStatementY),
eBindExpression(eBindings([("x", IEvNumber(2.))]), exampleStatementY),
"Ok((:$_exportBindings_$ (:$_setBindings_$ @{x: 2} :y 1)) context: @{x: 2})",
)
// Now let's reduce that expression
testMacroEval(
[],
eBindExpression(eBindings([("x", IevNumber(2.))]), exampleStatementY),
eBindExpression(eBindings([("x", IEvNumber(2.))]), exampleStatementY),
"Ok(@{x: 2,y: 1})",
)
// When bindings are missing the context is injected. This must be the first and last statement of a block
testMacroEval(
[("z", IevNumber(99.))],
[("z", IEvNumber(99.))],
eBindExpressionDefault(exampleStatementY),
"Ok(@{y: 1,z: 99})",
)
@ -115,7 +115,7 @@ describe("block", () => {
"Ok((:$$_bindExpression_$$ {(:$_let_$ :y (:add :x 1)); :y}))",
)
testMacroEval(
[("x", IevNumber(1.))],
[("x", IEvNumber(1.))],
eBlock(list{
eBlock(list{
eLetStatement("y", eFunction("add", list{eSymbol("x"), eNumber(1.)})),
@ -135,12 +135,12 @@ describe("lambda", () => {
testMacro([], callLambdaExpression, "Ok(((:$$_lambda_$$ [y] :y) 1))")
testMacroEval([], callLambdaExpression, "Ok(1)")
// 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
let lambdaExpression = eFunction(
"$$_lambda_$$",
list{eArrayString(["z"]), eFunction("add", list{eSymbol("y"), eSymbol("z")})},
)
let callLambdaExpression = eList(list{lambdaExpression, eNumber(1.)})
testMacroEval([("y", IevNumber(666.))], callLambdaExpression, "Ok(667)")
testMacroEval([("y", IEvNumber(666.))], callLambdaExpression, "Ok(667)")
})

View File

@ -6,11 +6,11 @@ module Module = Reducer_Category_Module
let removeDefaultsInternal = (iev: InternalExpressionValue.expressionValue) => {
switch iev {
| InternalExpressionValue.IevModule(nameSpace) =>
| InternalExpressionValue.IEvModule(nameSpace) =>
Module.removeOther(
nameSpace,
ReducerInterface.StdLib.internalStdLib,
)->InternalExpressionValue.IevModule
)->InternalExpressionValue.IEvModule
| value => value
}
}

View File

@ -5,14 +5,14 @@ open Jest
open ExpectJs
describe("eval", () => {
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("String", () => expect(MathJs.Eval.eval("'hello'"))->toEqual(Ok(IevString("hello"))))
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("String", () => expect(MathJs.Eval.eval("'hello'"))->toEqual(Ok(IEvString("hello"))))
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 expr", () => expect(MathJs.Eval.eval("2>1"))->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))))
})
describe("errors", () => {

View File

@ -75,13 +75,13 @@ module FRType = {
let rec toFrValue = (r: expressionValue): option<frValue> =>
switch r {
| IevNumber(f) => Some(FRValueNumber(f))
| IevString(f) => Some(FRValueString(f))
| IevDistribution(f) => Some(FRValueDistOrNumber(FRValueDist(f)))
| IevLambda(f) => Some(FRValueLambda(f))
| IevArray(elements) =>
| IEvNumber(f) => Some(FRValueNumber(f))
| IEvString(f) => Some(FRValueString(f))
| IEvDistribution(f) => Some(FRValueDistOrNumber(FRValueDist(f)))
| IEvLambda(f) => Some(FRValueLambda(f))
| IEvArray(elements) =>
elements->E.A2.fmap(toFrValue)->E.A.O.openIfAllSome->E.O2.fmap(r => FRValueArray(r))
| IevRecord(map) =>
| IEvRecord(map) =>
Belt.Map.String.toArray(map)
->E.A2.fmap(((key, item)) => item->toFrValue->E.O2.fmap(o => (key, o)))
->E.A.O.openIfAllSome
@ -92,26 +92,26 @@ module FRType = {
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> =>
switch (t, r) {
| (FRTypeAny, f) => toFrValue(f)
| (FRTypeString, IevString(f)) => Some(FRValueString(f))
| (FRTypeNumber, IevNumber(f)) => Some(FRValueNumber(f))
| (FRTypeDistOrNumber, IevNumber(f)) => Some(FRValueDistOrNumber(FRValueNumber(f)))
| (FRTypeDistOrNumber, IevDistribution(Symbolic(#Float(f)))) =>
| (FRTypeString, IEvString(f)) => Some(FRValueString(f))
| (FRTypeNumber, IEvNumber(f)) => Some(FRValueNumber(f))
| (FRTypeDistOrNumber, IEvNumber(f)) => Some(FRValueDistOrNumber(FRValueNumber(f)))
| (FRTypeDistOrNumber, IEvDistribution(Symbolic(#Float(f)))) =>
Some(FRValueDistOrNumber(FRValueNumber(f)))
| (FRTypeDistOrNumber, IevDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f)))
| (FRTypeNumeric, IevNumber(f)) => Some(FRValueNumber(f))
| (FRTypeNumeric, IevDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
| (FRTypeLambda, IevLambda(f)) => Some(FRValueLambda(f))
| (FRTypeArray(intendedType), IevArray(elements)) => {
| (FRTypeDistOrNumber, IEvDistribution(f)) => Some(FRValueDistOrNumber(FRValueDist(f)))
| (FRTypeNumeric, IEvNumber(f)) => Some(FRValueNumber(f))
| (FRTypeNumeric, IEvDistribution(Symbolic(#Float(f)))) => Some(FRValueNumber(f))
| (FRTypeLambda, IEvLambda(f)) => Some(FRValueLambda(f))
| (FRTypeArray(intendedType), IEvArray(elements)) => {
let el = elements->E.A2.fmap(matchWithExpressionValue(intendedType))
E.A.O.openIfAllSome(el)->E.O2.fmap(r => FRValueArray(r))
}
| (FRTypeDict(r), IevRecord(map)) =>
| (FRTypeDict(r), IEvRecord(map)) =>
map
->Belt.Map.String.toArray
->E.A2.fmap(((key, item)) => matchWithExpressionValue(r, item)->E.O2.fmap(o => (key, o)))
->E.A.O.openIfAllSome
->E.O2.fmap(r => FRValueDict(Js.Dict.fromArray(r)))
| (FRTypeRecord(recordParams), IevRecord(map)) => {
| (FRTypeRecord(recordParams), IEvRecord(map)) => {
let getAndMatch = (name, 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
@ -127,17 +127,17 @@ module FRType = {
let rec matchReverse = (e: frValue): expressionValue =>
switch e {
| FRValueNumber(f) => IevNumber(f)
| FRValueDistOrNumber(FRValueNumber(n)) => IevNumber(n)
| FRValueDistOrNumber(FRValueDist(n)) => IevDistribution(n)
| FRValueDist(dist) => IevDistribution(dist)
| FRValueArray(elements) => IevArray(elements->E.A2.fmap(matchReverse))
| FRValueNumber(f) => IEvNumber(f)
| FRValueDistOrNumber(FRValueNumber(n)) => IEvNumber(n)
| FRValueDistOrNumber(FRValueDist(n)) => IEvDistribution(n)
| FRValueDist(dist) => IEvDistribution(dist)
| FRValueArray(elements) => IEvArray(elements->E.A2.fmap(matchReverse))
| FRValueRecord(frValueRecord) => {
let map =
frValueRecord
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
->Belt.Map.String.fromArray
IevRecord(map)
IEvRecord(map)
}
| FRValueDict(frValueRecord) => {
let map =
@ -145,11 +145,11 @@ module FRType = {
->Js.Dict.entries
->E.A2.fmap(((name, value)) => (name, matchReverse(value)))
->Belt.Map.String.fromArray
IevRecord(map)
IEvRecord(map)
}
| FRValueLambda(l) => IevLambda(l)
| FRValueString(string) => IevString(string)
| FRValueVariant(string) => IevString(string)
| FRValueLambda(l) => IEvLambda(l)
| FRValueString(string) => IEvString(string)
| FRValueVariant(string) => IEvString(string)
| FRValueAny(f) => matchReverse(f)
}

View File

@ -4,11 +4,11 @@ let impossibleError = "Wrong inputs / Logically impossible"
module Wrappers = {
let symbolic = r => DistributionTypes.Symbolic(r)
let evDistribution = r => ReducerInterface_InternalExpressionValue.IevDistribution(r)
let evNumber = r => ReducerInterface_InternalExpressionValue.IevNumber(r)
let evArray = r => ReducerInterface_InternalExpressionValue.IevArray(r)
let evRecord = r => ReducerInterface_InternalExpressionValue.IevRecord(r)
let evString = r => ReducerInterface_InternalExpressionValue.IevString(r)
let evDistribution = r => ReducerInterface_InternalExpressionValue.IEvDistribution(r)
let evNumber = r => ReducerInterface_InternalExpressionValue.IEvNumber(r)
let evArray = r => ReducerInterface_InternalExpressionValue.IEvArray(r)
let evRecord = r => ReducerInterface_InternalExpressionValue.IEvRecord(r)
let evString = r => ReducerInterface_InternalExpressionValue.IEvString(r)
let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution
}

View File

@ -20,7 +20,7 @@ module Declaration = {
inputs
->E.A2.fmap(getMinMax)
->E.A.R.firstErrorOrOpen
->E.R2.fmap(args => ReducerInterface_InternalExpressionValue.IevDeclaration(
->E.R2.fmap(args => ReducerInterface_InternalExpressionValue.IEvDeclaration(
Declaration.make(lambda, args),
))
}
@ -43,7 +43,7 @@ let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
let expressionValue =
xyCoords
->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)),
))
expressionValue

View File

@ -11,7 +11,7 @@ let getType = (nameSpace: t, id: string) => {
let NameSpace(container) = nameSpace
Belt.Map.String.get(container, typeAliasesKey)->Belt.Option.flatMap(aliases =>
switch aliases {
| IevRecord(r) => Belt.Map.String.get(r, id)
| IEvRecord(r) => Belt.Map.String.get(r, id)
| _ => None
}
)
@ -21,7 +21,7 @@ let getTypeOf = (nameSpace: t, id: string) => {
let NameSpace(container) = nameSpace
Belt.Map.String.get(container, typeReferencesKey)->Belt.Option.flatMap(defs =>
switch defs {
| IevRecord(r) => Belt.Map.String.get(r, id)
| IEvRecord(r) => Belt.Map.String.get(r, id)
| _ => None
}
)
@ -41,23 +41,23 @@ let emptyMap: map = Belt.Map.String.empty
let setTypeAlias = (nameSpace: t, id: string, value): t => {
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 {
| IevRecord(r) => r
| IEvRecord(r) => r
| _ => 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
}
let setTypeOf = (nameSpace: t, id: string, value): t => {
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 {
| IevRecord(r) => r
| IEvRecord(r) => r
| _ => 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
}
@ -71,10 +71,10 @@ let emptyModule: t = NameSpace(Belt.Map.String.empty)
let fromTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceFromTypeScriptBindings
let toTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceToTypeScriptBindings
let toExpressionValue = (nameSpace: t): expressionValue => IevModule(nameSpace)
let toExpressionValue = (nameSpace: t): expressionValue => IEvModule(nameSpace)
let fromExpressionValue = (aValue: expressionValue): t =>
switch aValue {
| IevModule(nameSpace) => nameSpace
| IEvModule(nameSpace) => nameSpace
| _ => 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
}
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 =>
nameSpace->define(identifier, toExpressionValue(value))

View File

@ -10,7 +10,7 @@ let isOfResolvedType = (aType, aValue) => {
}
switch aType {
| IevTypeIdentifier(aTypeIdentifier) => caseTypeIdentifier(aTypeIdentifier, aValue)
| IEvTypeIdentifier(aTypeIdentifier) => caseTypeIdentifier(aTypeIdentifier, aValue)
| _ => false
}
}

View File

@ -32,12 +32,12 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
let constructRecord = arrayOfPairs => {
Belt.Array.map(arrayOfPairs, pairValue =>
switch pairValue {
| IevArray([IevString(key), valueValue]) => (key, valueValue)
| _ => ("wrong key type", pairValue->toStringWithType->IevString)
| IEvArray([IEvString(key), valueValue]) => (key, valueValue)
| _ => ("wrong key type", pairValue->toStringWithType->IEvString)
}
)
->Belt.Map.String.fromArray
->IevRecord
->IEvRecord
->Ok
}
@ -62,11 +62,11 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
let doAddArray = (originalA, b) => {
let a = originalA->Js.Array2.copy
let _ = Js.Array2.pushMany(a, b)
a->IevArray->Ok
a->IEvArray->Ok
}
let doAddString = (a, b) => {
let answer = Js.String2.concat(a, b)
answer->IevString->Ok
answer->IEvString->Ok
}
let inspect = (value: expressionValue) => {
@ -80,14 +80,14 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
}
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) =>
Module.setTypeAlias(bindings, symbol, value)->IevModule->Ok
Module.setTypeAlias(bindings, symbol, value)->IEvModule->Ok
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
@ -97,13 +97,13 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
let rNewElem = Lambda.doLambdaCall(aLambdaValue, list{elem}, environment, reducer)
rNewElem->Result.map(newElem =>
switch newElem {
| IevBool(true) => list{elem, ...acc}
| IEvBool(true) => list{elem, ...acc}
| _ => acc
}
)
})
)
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IevArray)
rMappedList->Result.map(mappedList => mappedList->Belt.List.toArray->IEvArray)
}
let doMapArray = (aValueArray, aLambdaValue) => {
@ -113,36 +113,36 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
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 = {
type t = SampleSetDist.t
let doLambdaCall = (aLambdaValue, list) =>
switch Lambda.doLambdaCall(aLambdaValue, list, environment, reducer) {
| Ok(IevNumber(f)) => Ok(f)
| Ok(IEvNumber(f)) => Ok(f)
| _ => Error(Operation.SampleMapNeedsNtoNFunction)
}
let toType = r =>
switch r {
| Ok(r) => Ok(IevDistribution(SampleSet(r)))
| Ok(r) => Ok(IEvDistribution(SampleSet(r)))
| Error(r) => Error(REDistributionError(SampleSetError(r)))
}
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))
}
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
}
let map3 = (t1: t, t2: t, t3: t, aLambdaValue) => {
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
}
}
@ -165,127 +165,127 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
let typeModifier_memberOf = (aType, anArray) => {
let newRecord = Belt.Map.String.fromArray([
("typeTag", IevString("typeIdentifier")),
("typeTag", IEvString("typeIdentifier")),
("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) => {
aRecord->Belt.Map.String.set("memberOf", anArray)->IevRecord->Ok
aRecord->Belt.Map.String.set("memberOf", anArray)->IEvRecord->Ok
}
let typeModifier_min = (aType, value) => {
let newRecord = Belt.Map.String.fromArray([
("typeTag", IevString("typeIdentifier")),
("typeTag", IEvString("typeIdentifier")),
("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) => {
aRecord->Belt.Map.String.set("min", value)->IevRecord->Ok
aRecord->Belt.Map.String.set("min", value)->IEvRecord->Ok
}
let typeModifier_max = (aType, value) => {
let newRecord = Belt.Map.String.fromArray([
("typeTag", IevString("typeIdentifier")),
("typeTag", IEvString("typeIdentifier")),
("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) =>
aRecord->Belt.Map.String.set("max", value)->IevRecord->Ok
aRecord->Belt.Map.String.set("max", value)->IEvRecord->Ok
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 newRecord = Belt.Map.String.fromArray([
("typeTag", IevString("typeOr")),
("typeTag", IEvString("typeOr")),
("typeOr", evArray),
])
newRecord->IevRecord->Ok
newRecord->IEvRecord->Ok
}
let typeFunction = anArray => {
let output = Belt.Array.getUnsafe(anArray, Js.Array2.length(anArray) - 1)
let inputs = Js.Array2.slice(anArray, ~start=0, ~end_=-1)
let newRecord = Belt.Map.String.fromArray([
("typeTag", IevString("typeFunction")),
("inputs", IevArray(inputs)),
("typeTag", IEvString("typeFunction")),
("inputs", IEvArray(inputs)),
("output", output),
])
newRecord->IevRecord->Ok
newRecord->IEvRecord->Ok
}
switch call {
| ("$_atIndex_$", [IevArray(aValueArray), IevNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
| ("$_atIndex_$", [IevModule(dict), IevString(sIndex)]) => moduleAtIndex(dict, sIndex)
| ("$_atIndex_$", [IevRecord(dict), IevString(sIndex)]) => recordAtIndex(dict, sIndex)
| ("$_constructArray_$", [IevArray(aValueArray)]) => IevArray(aValueArray)->Ok
| ("$_constructRecord_$", [IevArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
| ("$_exportBindings_$", [IevModule(nameSpace)]) => doExportBindings(nameSpace)
| ("$_setBindings_$", [IevModule(nameSpace), IevSymbol(symbol), value]) =>
| ("$_atIndex_$", [IEvArray(aValueArray), IEvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
| ("$_atIndex_$", [IEvModule(dict), IEvString(sIndex)]) => moduleAtIndex(dict, sIndex)
| ("$_atIndex_$", [IEvRecord(dict), IEvString(sIndex)]) => recordAtIndex(dict, sIndex)
| ("$_constructArray_$", [IEvArray(aValueArray)]) => IEvArray(aValueArray)->Ok
| ("$_constructRecord_$", [IEvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
| ("$_exportBindings_$", [IEvModule(nameSpace)]) => doExportBindings(nameSpace)
| ("$_setBindings_$", [IEvModule(nameSpace), IEvSymbol(symbol), value]) =>
doSetBindings(nameSpace, symbol, value)
| ("$_setTypeAliasBindings_$", [IevModule(nameSpace), IevTypeIdentifier(symbol), value]) =>
| ("$_setTypeAliasBindings_$", [IEvModule(nameSpace), IEvTypeIdentifier(symbol), value]) =>
doSetTypeAliasBindings(nameSpace, symbol, value)
| ("$_setTypeOfBindings_$", [IevModule(nameSpace), IevSymbol(symbol), value]) =>
| ("$_setTypeOfBindings_$", [IEvModule(nameSpace), IEvSymbol(symbol), value]) =>
doSetTypeOfBindings(nameSpace, symbol, value)
| ("$_typeModifier_memberOf_$", [IevTypeIdentifier(typeIdentifier), IevArray(arr)]) =>
typeModifier_memberOf(IevTypeIdentifier(typeIdentifier), IevArray(arr))
| ("$_typeModifier_memberOf_$", [IevRecord(typeRecord), IevArray(arr)]) =>
typeModifier_memberOf_update(typeRecord, IevArray(arr))
| ("$_typeModifier_min_$", [IevTypeIdentifier(typeIdentifier), value]) =>
typeModifier_min(IevTypeIdentifier(typeIdentifier), value)
| ("$_typeModifier_min_$", [IevRecord(typeRecord), value]) =>
| ("$_typeModifier_memberOf_$", [IEvTypeIdentifier(typeIdentifier), IEvArray(arr)]) =>
typeModifier_memberOf(IEvTypeIdentifier(typeIdentifier), IEvArray(arr))
| ("$_typeModifier_memberOf_$", [IEvRecord(typeRecord), IEvArray(arr)]) =>
typeModifier_memberOf_update(typeRecord, IEvArray(arr))
| ("$_typeModifier_min_$", [IEvTypeIdentifier(typeIdentifier), value]) =>
typeModifier_min(IEvTypeIdentifier(typeIdentifier), value)
| ("$_typeModifier_min_$", [IEvRecord(typeRecord), value]) =>
typeModifier_min_update(typeRecord, value)
| ("$_typeModifier_max_$", [IevTypeIdentifier(typeIdentifier), value]) =>
typeModifier_max(IevTypeIdentifier(typeIdentifier), value)
| ("$_typeModifier_max_$", [IevRecord(typeRecord), value]) =>
| ("$_typeModifier_max_$", [IEvTypeIdentifier(typeIdentifier), value]) =>
typeModifier_max(IEvTypeIdentifier(typeIdentifier), value)
| ("$_typeModifier_max_$", [IEvRecord(typeRecord), value]) =>
typeModifier_max_update(typeRecord, value)
| ("$_typeModifier_opaque_$", [IevRecord(typeRecord)]) => typeModifier_opaque_update(typeRecord)
| ("$_typeOr_$", [IevArray(arr)]) => typeOr(IevArray(arr))
| ("$_typeFunction_$", [IevArray(arr)]) => typeFunction(arr)
| ("concat", [IevArray(aValueArray), IevArray(bValueArray)]) =>
| ("$_typeModifier_opaque_$", [IEvRecord(typeRecord)]) => typeModifier_opaque_update(typeRecord)
| ("$_typeOr_$", [IEvArray(arr)]) => typeOr(IEvArray(arr))
| ("$_typeFunction_$", [IEvArray(arr)]) => typeFunction(arr)
| ("concat", [IEvArray(aValueArray), IEvArray(bValueArray)]) =>
doAddArray(aValueArray, bValueArray)
| ("concat", [IevString(aValueString), IevString(bValueString)]) =>
| ("concat", [IEvString(aValueString), IEvString(bValueString)]) =>
doAddString(aValueString, bValueString)
| ("inspect", [value, IevString(label)]) => inspectLabel(value, label)
| ("inspect", [value, IEvString(label)]) => inspectLabel(value, label)
| ("inspect", [value]) => inspect(value)
| ("filter", [IevArray(aValueArray), IevLambda(aLambdaValue)]) =>
| ("filter", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
doKeepArray(aValueArray, aLambdaValue)
| ("map", [IevArray(aValueArray), IevLambda(aLambdaValue)]) =>
| ("map", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
doMapArray(aValueArray, aLambdaValue)
| ("mapSamples", [IevDistribution(SampleSet(dist)), IevLambda(aLambdaValue)]) =>
| ("mapSamples", [IEvDistribution(SampleSet(dist)), IEvLambda(aLambdaValue)]) =>
SampleMap.map1(dist, aLambdaValue)
| (
"mapSamples2",
[
IevDistribution(SampleSet(dist1)),
IevDistribution(SampleSet(dist2)),
IevLambda(aLambdaValue),
IEvDistribution(SampleSet(dist1)),
IEvDistribution(SampleSet(dist2)),
IEvLambda(aLambdaValue),
],
) =>
SampleMap.map2(dist1, dist2, aLambdaValue)
| (
"mapSamples3",
[
IevDistribution(SampleSet(dist1)),
IevDistribution(SampleSet(dist2)),
IevDistribution(SampleSet(dist3)),
IevLambda(aLambdaValue),
IEvDistribution(SampleSet(dist1)),
IEvDistribution(SampleSet(dist2)),
IEvDistribution(SampleSet(dist3)),
IEvLambda(aLambdaValue),
],
) =>
SampleMap.map3(dist1, dist2, dist3, aLambdaValue)
| ("reduce", [IevArray(aValueArray), initialValue, IevLambda(aLambdaValue)]) =>
| ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
doReduceArray(aValueArray, initialValue, aLambdaValue)
| ("reduceReverse", [IevArray(aValueArray), initialValue, IevLambda(aLambdaValue)]) =>
| ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
| ("reverse", [IevArray(aValueArray)]) => aValueArray->Belt.Array.reverse->IevArray->Ok
| (_, [IevBool(_)])
| (_, [IevNumber(_)])
| (_, [IevString(_)])
| (_, [IevBool(_), IevBool(_)])
| (_, [IevNumber(_), IevNumber(_)])
| (_, [IevString(_), IevString(_)]) =>
| ("reverse", [IEvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->IEvArray->Ok
| (_, [IEvBool(_)])
| (_, [IEvNumber(_)])
| (_, [IEvString(_)])
| (_, [IEvBool(_), IEvBool(_)])
| (_, [IEvNumber(_), IEvNumber(_)])
| (_, [IEvString(_), IEvString(_)]) =>
callMathJs(call)
| call =>
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error

View File

@ -52,7 +52,7 @@ let dispatchMacroCall = (
let doBindStatement = (bindingExpr: expression, statement: expression, environment) => {
let defaultStatement = ErrorValue.REAssignmentExpected->Error
switch statement {
| ExpressionT.EList(list{ExpressionT.EValue(IevCall(callName)), symbolExpr, statement}) => {
| ExpressionT.EList(list{ExpressionT.EValue(IEvCall(callName)), symbolExpr, statement}) => {
let setBindingsFn = correspondingSetBindingsFn(callName)
if setBindingsFn !== "" {
useExpressionToSetBindings(bindingExpr, environment, statement, (
@ -78,7 +78,7 @@ let dispatchMacroCall = (
) => boundStatement)
switch statement {
| ExpressionT.EList(list{ExpressionT.EValue(IevCall(callName)), symbolExpr, statement}) => {
| ExpressionT.EList(list{ExpressionT.EValue(IEvCall(callName)), symbolExpr, statement}) => {
let setBindingsFn = correspondingSetBindingsFn(callName)
if setBindingsFn !== "" {
useExpressionToSetBindings(bindingExpr, environment, statement, (
@ -137,11 +137,11 @@ let dispatchMacroCall = (
let rCondition = reduceExpression(blockCondition, bindings, environment)
rCondition->Result.flatMap(conditionValue =>
switch conditionValue {
| ExpressionValue.IevBool(false) => {
| ExpressionValue.IEvBool(false) => {
let ifFalseBlock = eBlock(list{ifFalse})
ExpressionWithContext.withContext(ifFalseBlock, bindings)->Ok
}
| ExpressionValue.IevBool(true) => {
| ExpressionValue.IEvBool(true) => {
let ifTrueBlock = eBlock(list{ifTrue})
ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok
}
@ -156,32 +156,32 @@ let dispatchMacroCall = (
> =>
switch aList {
| list{
ExpressionT.EValue(IevCall("$$_bindStatement_$$")),
ExpressionT.EValue(IEvCall("$$_bindStatement_$$")),
bindingExpr: ExpressionT.expression,
statement,
} =>
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
doBindStatement(eModule(bindings), statement, environment)
| list{
ExpressionT.EValue(IevCall("$$_bindExpression_$$")),
ExpressionT.EValue(IEvCall("$$_bindExpression_$$")),
bindingExpr: ExpressionT.expression,
expression,
} =>
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
doBindExpression(eModule(bindings), expression, environment)
| list{ExpressionT.EValue(IevCall("$$_block_$$")), ...exprs} =>
| list{ExpressionT.EValue(IEvCall("$$_block_$$")), ...exprs} =>
doBlock(exprs, bindings, environment)
| list{
ExpressionT.EValue(IevCall("$$_lambda_$$")),
ExpressionT.EValue(IevArrayString(parameters)),
ExpressionT.EValue(IEvCall("$$_lambda_$$")),
ExpressionT.EValue(IEvArrayString(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)
| _ => ExpressionWithContext.noContext(ExpressionT.EList(aList))->Ok
}

View File

@ -36,7 +36,7 @@ let rec reduceExpression = (expression: t, bindings: T.bindings, environment: en
| T.EValue(value) => value->Ok
| T.EList(list) =>
switch list {
| list{EValue(IevCall(fName)), ..._args} =>
| list{EValue(IEvCall(fName)), ..._args} =>
switch Macro.isMacroName(fName) {
// A macro expands then reduces itself
| true => Macro.doMacroCall(expression, bindings, environment, reduceExpression)
@ -75,7 +75,7 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
'e,
> =>
switch valueList {
| list{IevCall(fName), ...args} => {
| list{IEvCall(fName), ...args} => {
let rCheckedArgs = switch fName {
| "$_setBindings_$" | "$_setTypeOfBindings_$" | "$_setTypeAliasBindings_$" => args->Ok
| _ => args->Lambda.checkIfReduced
@ -85,14 +85,14 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
(fName, checkedArgs->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
)
}
| list{IevLambda(_)} =>
| list{IEvLambda(_)} =>
// TODO: remove on solving issue#558
valueList
->Lambda.checkIfReduced
->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
->Lambda.checkIfReduced
->Result.flatMap(checkedArgs =>
@ -103,7 +103,7 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
valueList
->Lambda.checkIfReduced
->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> => {
evaluateUsingOptions(~environment=None, ~externalBindings=None, code)

View File

@ -21,7 +21,7 @@ let rec replaceSymbols = (bindings: ExpressionT.bindings, expression: expression
replaceSymbolOnValue(bindings, value)->Result.map(evValue => evValue->ExpressionT.EValue)
| ExpressionT.EList(list) =>
switch list {
| list{EValue(IevCall(fName)), ..._args} =>
| list{EValue(IEvCall(fName)), ..._args} =>
switch isMacroName(fName) {
// A macro reduces itself so we dont dive in it
| true => expression->Ok
@ -43,12 +43,12 @@ and replaceSymbolsOnExpressionList = (bindings, list) => {
}
and replaceSymbolOnValue = (bindings, evValue: expressionValue) =>
switch evValue {
| IevSymbol(symbol) => Module.getWithDefault(bindings, symbol, evValue)->Ok
| IevCall(symbol) => Module.getWithDefault(bindings, symbol, evValue)->checkIfCallable
| IEvSymbol(symbol) => Module.getWithDefault(bindings, symbol, evValue)->Ok
| IEvCall(symbol) => Module.getWithDefault(bindings, symbol, evValue)->checkIfCallable
| _ => evValue->Ok
}
and checkIfCallable = (evValue: expressionValue) =>
switch evValue {
| IevCall(_) | IevLambda(_) => evValue->Ok
| IEvCall(_) | IEvLambda(_) => evValue->Ok
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
}

View File

@ -12,16 +12,16 @@ type internalCode = ReducerInterface_InternalExpressionValue.internalCode
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)>) =>
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 fn = fName->eCall
@ -33,7 +33,7 @@ let eLambda = (
context: BExpressionValue.nameSpace,
expr: expression,
) => {
BExpressionValue.IevLambda({
BExpressionValue.IEvLambda({
parameters: parameters,
context: context,
body: NotFFI(expr)->castExpressionToInternalCode,
@ -42,27 +42,27 @@ let eLambda = (
let eLambdaFFI = (parameters: array<string>, ffiFn: ffiFn) => {
let context = BModule.emptyModule
BExpressionValue.IevLambda({
BExpressionValue.IEvLambda({
parameters: parameters,
context: context,
body: FFI(ffiFn)->castExpressionToInternalCode,
})->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 eBlock = (exprs: list<expression>): expression => eFunction("$$_block_$$", exprs)
let eModule = (nameSpace: BExpressionValue.nameSpace): expression =>
nameSpace->BExpressionValue.IevModule->BExpressionT.EValue
nameSpace->BExpressionValue.IEvModule->BExpressionT.EValue
let eLetStatement = (symbol: string, valueExpression: expression): expression =>
eFunction("$_let_$", list{eSymbol(symbol), valueExpression})
@ -80,7 +80,7 @@ let eBindExpressionDefault = (expression: expression): expression =>
eFunction("$$_bindExpression_$$", list{expression})
let eIdentifier = (name: string): expression =>
name->BExpressionValue.IevSymbol->BExpressionT.EValue
name->BExpressionValue.IEvSymbol->BExpressionT.EValue
let eTypeIdentifier = (name: string): expression =>
name->BExpressionValue.IevTypeIdentifier->BExpressionT.EValue
name->BExpressionValue.IEvTypeIdentifier->BExpressionT.EValue

View File

@ -29,7 +29,7 @@ let checkIfReduced = (args: list<expressionValue>) =>
args->Belt.List.reduceReverse(Ok(list{}), (rAcc, arg) =>
rAcc->Result.flatMap(acc =>
switch arg {
| IevSymbol(symbol) => ErrorValue.RESymbolNotFound(symbol)->Error
| IEvSymbol(symbol) => ErrorValue.RESymbolNotFound(symbol)->Error
| _ => list{arg, ...acc}->Ok
}
)

View File

@ -28,7 +28,7 @@ type reducerFn = (
*/
let rec toString = expression =>
switch expression {
| EList(list{EValue(IevCall("$$_block_$$")), ...statements}) =>
| EList(list{EValue(IEvCall("$$_block_$$")), ...statements}) =>
`{${Belt.List.map(statements, aValue => toString(aValue))
->Extra.List.interperse("; ")
->Belt.List.toArray

View File

@ -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
*/
let jsToIev = (jsValue): result<expressionValue, errorValue> =>
let jsToIEv = (jsValue): result<expressionValue, errorValue> =>
switch Js.typeof(jsValue) {
| "boolean" => jsValue->castBool->IevBool->Ok
| "number" => jsValue->castNumber->IevNumber->Ok
| "string" => jsValue->castString->IevString->Ok
| "boolean" => jsValue->castBool->IEvBool->Ok
| "number" => jsValue->castNumber->IEvNumber->Ok
| "string" => jsValue->castString->IEvString->Ok
| other => RETodo(`Unhandled MathJs literal type: ${Js.String.make(other)}`)->Error
}

View File

@ -20,7 +20,7 @@ let eval__: string => 'a = %raw(`function (expr) { return {value: Mathjs.evaluat
let eval = (expr: string): result<expressionValue, errorValue> => {
try {
let answer = eval__(expr)
answer["value"]->JavaScript.Gate.jsToIev
answer["value"]->JavaScript.Gate.jsToIEv
} catch {
| Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error
}

View File

@ -5,23 +5,23 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => {
switch call {
| ("toString", [IevDate(t)]) => EV.IevString(DateTime.Date.toString(t))->Ok->Some
| ("makeDateFromYear", [IevNumber(year)]) =>
| ("toString", [IEvDate(t)]) => EV.IEvString(DateTime.Date.toString(t))->Ok->Some
| ("makeDateFromYear", [IEvNumber(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
}
| ("dateFromNumber", [IevNumber(f)]) => EV.IevDate(DateTime.Date.fromFloat(f))->Ok->Some
| ("toNumber", [IevDate(f)]) => EV.IevNumber(DateTime.Date.toFloat(f))->Ok->Some
| ("subtract", [IevDate(d1), IevDate(d2)]) =>
| ("dateFromNumber", [IEvNumber(f)]) => EV.IEvDate(DateTime.Date.fromFloat(f))->Ok->Some
| ("toNumber", [IEvDate(f)]) => EV.IEvNumber(DateTime.Date.toFloat(f))->Ok->Some
| ("subtract", [IEvDate(d1), IEvDate(d2)]) =>
switch DateTime.Date.subtract(d1, d2) {
| Ok(d) => EV.IevTimeDuration(d)->Ok
| Ok(d) => EV.IEvTimeDuration(d)->Ok
| Error(e) => Error(RETodo(e))
}->Some
| ("subtract", [IevDate(d1), IevTimeDuration(d2)]) =>
EV.IevDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some
| ("add", [IevDate(d1), IevTimeDuration(d2)]) =>
EV.IevDate(DateTime.Date.addDuration(d1, d2))->Ok->Some
| ("subtract", [IEvDate(d1), IEvTimeDuration(d2)]) =>
EV.IEvDate(DateTime.Date.subtractDuration(d1, d2))->Ok->Some
| ("add", [IEvDate(d1), IEvTimeDuration(d2)]) =>
EV.IEvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some
| _ => None
}
}

View File

@ -5,31 +5,31 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => {
switch call {
| ("toString", [IevTimeDuration(t)]) => EV.IevString(DateTime.Duration.toString(t))->Ok->Some
| ("minutes", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("fromUnit_minutes", [IevNumber(f)]) =>
EV.IevTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("hours", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
| ("fromUnit_hours", [IevNumber(f)]) =>
EV.IevTimeDuration(DateTime.Duration.fromHours(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
| ("years", [IevNumber(f)]) => EV.IevTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
| ("fromUnit_years", [IevNumber(f)]) =>
EV.IevTimeDuration(DateTime.Duration.fromYears(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
| ("toDays", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toDays(f))->Ok->Some
| ("toYears", [IevTimeDuration(f)]) => EV.IevNumber(DateTime.Duration.toYears(f))->Ok->Some
| ("add", [IevTimeDuration(d1), IevTimeDuration(d2)]) =>
EV.IevTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some
| ("subtract", [IevTimeDuration(d1), IevTimeDuration(d2)]) =>
EV.IevTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some
| ("multiply", [IevTimeDuration(d1), IevNumber(d2)]) =>
EV.IevTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some
| ("divide", [IevTimeDuration(d1), IevNumber(d2)]) =>
EV.IevTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
| ("divide", [IevTimeDuration(d1), IevTimeDuration(d2)]) => EV.IevNumber(d1 /. d2)->Ok->Some
| ("toString", [IEvTimeDuration(t)]) => EV.IEvString(DateTime.Duration.toString(t))->Ok->Some
| ("minutes", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("fromUnit_minutes", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("hours", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
| ("fromUnit_hours", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromHours(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
| ("years", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
| ("fromUnit_years", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromYears(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
| ("toDays", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toDays(f))->Ok->Some
| ("toYears", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toYears(f))->Ok->Some
| ("add", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) =>
EV.IEvTimeDuration(DateTime.Duration.add(d1, d2))->Ok->Some
| ("subtract", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) =>
EV.IEvTimeDuration(DateTime.Duration.subtract(d1, d2))->Ok->Some
| ("multiply", [IEvTimeDuration(d1), IEvNumber(d2)]) =>
EV.IEvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some
| ("divide", [IEvTimeDuration(d1), IEvNumber(d2)]) =>
EV.IEvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
| ("divide", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) => EV.IEvNumber(d1 /. d2)->Ok->Some
| _ => None
}
}

View File

@ -23,9 +23,9 @@ module Helpers = {
DistributionTypes.genericDist,
)> =>
switch args {
| [IevDistribution(a), IevDistribution(b)] => Some((a, b))
| [IevNumber(a), IevDistribution(b)] => Some((GenericDist.fromFloat(a), b))
| [IevDistribution(a), IevNumber(b)] => Some((a, GenericDist.fromFloat(b)))
| [IEvDistribution(a), IEvDistribution(b)] => Some((a, b))
| [IEvNumber(a), IEvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
| [IEvDistribution(a), IEvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
| _ => None
}
@ -82,7 +82,7 @@ module Helpers = {
let parseNumber = (args: expressionValue): Belt.Result.t<float, string> =>
switch args {
| IevNumber(x) => Ok(x)
| IEvNumber(x) => Ok(x)
| _ => Error("Not a number")
}
@ -91,8 +91,8 @@ module Helpers = {
let parseDist = (args: expressionValue): Belt.Result.t<DistributionTypes.genericDist, string> =>
switch args {
| IevDistribution(x) => Ok(x)
| IevNumber(x) => Ok(GenericDist.fromFloat(x))
| IEvDistribution(x) => Ok(x)
| IEvNumber(x) => Ok(GenericDist.fromFloat(x))
| _ => Error("Not a distribution")
}
@ -128,12 +128,12 @@ module Helpers = {
let error = (err: string): DistributionOperation.outputType =>
err->DistributionTypes.ArgumentError->GenDistError
switch args {
| [IevArray(distributions)] =>
| [IEvArray(distributions)] =>
switch parseDistributionArray(distributions) {
| Ok(distrs) => mixtureWithDefaultWeights(distrs, ~env)
| Error(err) => error(err)
}
| [IevArray(distributions), IevArray(weights)] =>
| [IEvArray(distributions), IEvArray(weights)] =>
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts, ~env)
| (Error(err), Ok(_)) => error(err)
@ -142,7 +142,7 @@ module Helpers = {
}
| _ =>
switch E.A.last(args) {
| Some(IevArray(b)) => {
| Some(IEvArray(b)) => {
let weights = parseNumberArray(b)
let distributions = parseDistributionArray(
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
@ -152,8 +152,8 @@ module Helpers = {
| Error(err) => error(err)
}
}
| Some(IevNumber(_))
| Some(IevDistribution(_)) =>
| Some(IEvNumber(_))
| Some(IEvDistribution(_)) =>
switch parseDistributionArray(args) {
| Ok(distributions) => mixtureWithDefaultWeights(distributions, ~env)
| Error(err) => error(err)
@ -200,14 +200,14 @@ let dispatchToGenericOutput = (
): option<DistributionOperation.outputType> => {
let (fnName, args) = call
switch (fnName, args) {
| ("triangular" as fnName, [IevNumber(f1), IevNumber(f2), IevNumber(f3)]) =>
| ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) =>
SymbolicConstructors.threeFloat(fnName)
->E.R.bind(r => r(f1, f2, f3))
->SymbolicConstructors.symbolicResultToOutput
| ("sample", [IevDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env)
| ("sampleN", [IevDistribution(dist), IevNumber(n)]) =>
| ("sample", [IEvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env)
| ("sampleN", [IEvDistribution(dist), IEvNumber(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 {
| "mean" => #Mean
| "stdev" => #Stdev
@ -219,13 +219,13 @@ let dispatchToGenericOutput = (
}
Helpers.toFloatFn(fn, dist, ~env)
}
| ("integralSum", [IevDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
| ("toString", [IevDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
| ("sparkline", [IevDistribution(dist)]) =>
| ("integralSum", [IEvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
| ("toString", [IEvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
| ("sparkline", [IEvDistribution(dist)]) =>
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)
| ("exp", [IevDistribution(a)]) =>
| ("exp", [IEvDistribution(a)]) =>
// https://mathjs.org/docs/reference/functions/exp.html
Helpers.twoDiststoDistFn(
Algebraic(AsDefault),
@ -234,62 +234,62 @@ let dispatchToGenericOutput = (
a,
~env,
)->Some
| ("normalize", [IevDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
| ("klDivergence", [IevDistribution(prediction), IevDistribution(answer)]) =>
| ("normalize", [IEvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
| ("klDivergence", [IEvDistribution(prediction), IEvDistribution(answer)]) =>
Some(DistributionOperation.run(FromDist(ToScore(KLDivergence(answer)), prediction), ~env))
| (
"klDivergence",
[IevDistribution(prediction), IevDistribution(answer), IevDistribution(prior)],
[IEvDistribution(prediction), IEvDistribution(answer), IEvDistribution(prior)],
) =>
Helpers.klDivergenceWithPrior(prediction, answer, prior, env)
| (
"logScoreWithPointAnswer",
[IevDistribution(prediction), IevNumber(answer), IevDistribution(prior)],
[IEvDistribution(prediction), IEvNumber(answer), IEvDistribution(prior)],
)
| (
"logScoreWithPointAnswer",
[
IevDistribution(prediction),
IevDistribution(Symbolic(#Float(answer))),
IevDistribution(prior),
IEvDistribution(prediction),
IEvDistribution(Symbolic(#Float(answer))),
IEvDistribution(prior),
],
) =>
DistributionOperation.run(
FromDist(ToScore(LogScore(answer, prior->Some)), prediction),
~env,
)->Some
| ("logScoreWithPointAnswer", [IevDistribution(prediction), IevNumber(answer)])
| ("logScoreWithPointAnswer", [IEvDistribution(prediction), IEvNumber(answer)])
| (
"logScoreWithPointAnswer",
[IevDistribution(prediction), IevDistribution(Symbolic(#Float(answer)))],
[IEvDistribution(prediction), IEvDistribution(Symbolic(#Float(answer)))],
) =>
DistributionOperation.run(FromDist(ToScore(LogScore(answer, None)), prediction), ~env)->Some
| ("isNormalized", [IevDistribution(dist)]) => Helpers.toBoolFn(IsNormalized, dist, ~env)
| ("toPointSet", [IevDistribution(dist)]) => Helpers.toDistFn(ToPointSet, dist, ~env)
| ("scaleLog", [IevDistribution(dist)]) =>
| ("isNormalized", [IEvDistribution(dist)]) => Helpers.toBoolFn(IsNormalized, dist, ~env)
| ("toPointSet", [IEvDistribution(dist)]) => Helpers.toDistFn(ToPointSet, dist, ~env)
| ("scaleLog", [IEvDistribution(dist)]) =>
Helpers.toDistFn(Scale(#Logarithm, MagicNumbers.Math.e), dist, ~env)
| ("scaleLog10", [IevDistribution(dist)]) => Helpers.toDistFn(Scale(#Logarithm, 10.0), dist, ~env)
| ("scaleLog", [IevDistribution(dist), IevNumber(float)]) =>
| ("scaleLog10", [IEvDistribution(dist)]) => Helpers.toDistFn(Scale(#Logarithm, 10.0), dist, ~env)
| ("scaleLog", [IEvDistribution(dist), IEvNumber(float)]) =>
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)
| ("scaleMultiply", [IevDistribution(dist), IevNumber(float)]) =>
| ("scaleMultiply", [IEvDistribution(dist), IEvNumber(float)]) =>
Helpers.toDistFn(Scale(#Multiply, float), dist, ~env)
| ("scalePow", [IevDistribution(dist), IevNumber(float)]) =>
| ("scalePow", [IEvDistribution(dist), IEvNumber(float)]) =>
Helpers.toDistFn(Scale(#Power, float), dist, ~env)
| ("scaleExp", [IevDistribution(dist)]) =>
| ("scaleExp", [IEvDistribution(dist)]) =>
Helpers.toDistFn(Scale(#Power, MagicNumbers.Math.e), dist, ~env)
| ("cdf", [IevDistribution(dist), IevNumber(float)]) => Helpers.toFloatFn(#Cdf(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)
| ("quantile", [IevDistribution(dist), IevNumber(float)]) =>
| ("cdf", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Cdf(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)
| ("quantile", [IEvDistribution(dist), IEvNumber(float)]) =>
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)
| ("toSampleSet", [IevDistribution(dist)]) =>
| ("toSampleSet", [IEvDistribution(dist)]) =>
Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env)
| ("toList", [IevDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
| ("fromSamples", [IevArray(inputArray)]) => {
| ("toList", [IEvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
| ("fromSamples", [IEvArray(inputArray)]) => {
let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x)
let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors)
switch parsedArray {
@ -297,15 +297,15 @@ let dispatchToGenericOutput = (
| Error(e) => GenDistError(SampleSetError(e))
}->Some
}
| ("inspect", [IevDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
| ("truncateLeft", [IevDistribution(dist), IevNumber(float)]) =>
| ("inspect", [IEvDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
| ("truncateLeft", [IEvDistribution(dist), IEvNumber(float)]) =>
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)
| ("truncate", [IevDistribution(dist), IevNumber(float1), IevNumber(float2)]) =>
| ("truncate", [IEvDistribution(dist), IEvNumber(float1), IEvNumber(float2)]) =>
Helpers.toDistFn(Truncate(Some(float1), Some(float2)), dist, ~env)
| ("mx" | "mixture", args) => Helpers.mixture(args, ~env)->Some
| ("log", [IevDistribution(a)]) =>
| ("log", [IEvDistribution(a)]) =>
Helpers.twoDiststoDistFn(
Algebraic(AsDefault),
"log",
@ -313,7 +313,7 @@ let dispatchToGenericOutput = (
GenericDist.fromFloat(MagicNumbers.Math.e),
~env,
)->Some
| ("log10", [IevDistribution(a)]) =>
| ("log10", [IEvDistribution(a)]) =>
Helpers.twoDiststoDistFn(
Algebraic(AsDefault),
"log",
@ -321,7 +321,7 @@ let dispatchToGenericOutput = (
GenericDist.fromFloat(10.0),
~env,
)->Some
| ("unaryMinus", [IevDistribution(a)]) =>
| ("unaryMinus", [IEvDistribution(a)]) =>
Helpers.twoDiststoDistFn(
Algebraic(AsDefault),
"multiply",
@ -344,7 +344,7 @@ let dispatchToGenericOutput = (
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
Helpers.twoDiststoDistFn(Pointwise, arithmetic, fst, snd, ~env)
)
| ("dotExp", [IevDistribution(a)]) =>
| ("dotExp", [IEvDistribution(a)]) =>
Helpers.twoDiststoDistFn(
Pointwise,
"dotPow",
@ -361,12 +361,12 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
Reducer_ErrorValue.errorValue,
> =>
switch o {
| Dist(d) => Ok(ReducerInterface_InternalExpressionValue.IevDistribution(d))
| Float(d) => Ok(IevNumber(d))
| String(d) => Ok(IevString(d))
| Bool(d) => Ok(IevBool(d))
| Dist(d) => Ok(ReducerInterface_InternalExpressionValue.IEvDistribution(d))
| Float(d) => Ok(IEvNumber(d))
| String(d) => Ok(IEvString(d))
| Bool(d) => Ok(IEvBool(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))
}

View File

@ -7,21 +7,21 @@ type environment = ExternalExpressionValue.environment
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
type rec expressionValue =
| IevArray(array<expressionValue>) // FIXME: Convert
| IevArrayString(array<string>) // FIXME: Convert
| IevBool(bool)
| IevCall(string) // External function call
| IevDate(Js.Date.t)
| IevDeclaration(lambdaDeclaration)
| IevDistribution(DistributionTypes.genericDist)
| IevLambda(lambdaValue)
| IevModule(nameSpace) // FIXME: Convert
| IevNumber(float)
| IevRecord(map)
| IevString(string)
| IevSymbol(string)
| IevTimeDuration(float)
| IevTypeIdentifier(string)
| IEvArray(array<expressionValue>) // FIXME: Convert
| IEvArrayString(array<string>) // FIXME: Convert
| IEvBool(bool)
| IEvCall(string) // External function call
| IEvDate(Js.Date.t)
| IEvDeclaration(lambdaDeclaration)
| IEvDistribution(DistributionTypes.genericDist)
| IEvLambda(lambdaValue)
| IEvModule(nameSpace) // FIXME: Convert
| IEvNumber(float)
| IEvRecord(map)
| IEvString(string)
| IEvSymbol(string)
| IEvTimeDuration(float)
| IEvTypeIdentifier(string)
and map = Belt.Map.String.t<expressionValue>
and nameSpace = NameSpace(Belt.Map.String.t<expressionValue>)
and tmpExternalBindings = Js.Dict.t<expressionValue> // FIXME: Remove
@ -38,27 +38,27 @@ type functionCall = (string, array<expressionValue>)
let rec toString = aValue =>
switch aValue {
| IevArray(anArray) => {
| IEvArray(anArray) => {
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
`[${args}]`
}
| IevArrayString(anArray) => {
| IEvArrayString(anArray) => {
let args = anArray->Js.Array2.toString
`[${args}]`
}
| IevBool(aBool) => Js.String.make(aBool)
| IevCall(fName) => `:${fName}`
| IevDate(date) => DateTime.Date.toString(date)
| IevDeclaration(d) => Declaration.toString(d, r => toString(IevLambda(r)))
| IevDistribution(dist) => GenericDist.toString(dist)
| IevLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
| IevModule(m) => `@${m->toStringNameSpace}`
| IevNumber(aNumber) => Js.String.make(aNumber)
| IevRecord(aMap) => aMap->toStringMap
| IevString(aString) => `'${aString}'`
| IevSymbol(aString) => `:${aString}`
| IevTimeDuration(t) => DateTime.Duration.toString(t)
| IevTypeIdentifier(id) => `#${id}`
| IEvBool(aBool) => Js.String.make(aBool)
| IEvCall(fName) => `:${fName}`
| IEvDate(date) => DateTime.Date.toString(date)
| IEvDeclaration(d) => Declaration.toString(d, r => toString(IEvLambda(r)))
| IEvDistribution(dist) => GenericDist.toString(dist)
| IEvLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
| IEvModule(m) => `@${m->toStringNameSpace}`
| IEvNumber(aNumber) => Js.String.make(aNumber)
| IEvRecord(aMap) => aMap->toStringMap
| IEvString(aString) => `'${aString}'`
| IEvSymbol(aString) => `:${aString}`
| IEvTimeDuration(t) => DateTime.Duration.toString(t)
| IEvTypeIdentifier(id) => `#${id}`
}
and toStringMap = aMap => {
let pairs =
@ -75,21 +75,21 @@ and toStringNameSpace = nameSpace => {
let toStringWithType = aValue =>
switch aValue {
| IevArray(_) => `Array::${toString(aValue)}`
| IevArrayString(_) => `ArrayString::${toString(aValue)}`
| IevBool(_) => `Bool::${toString(aValue)}`
| IevCall(_) => `Call::${toString(aValue)}`
| IevDistribution(_) => `Distribution::${toString(aValue)}`
| IevLambda(_) => `Lambda::${toString(aValue)}`
| IevNumber(_) => `Number::${toString(aValue)}`
| IevRecord(_) => `Record::${toString(aValue)}`
| IevString(_) => `String::${toString(aValue)}`
| IevSymbol(_) => `Symbol::${toString(aValue)}`
| IevDate(_) => `Date::${toString(aValue)}`
| IevTimeDuration(_) => `Date::${toString(aValue)}`
| IevDeclaration(_) => `Declaration::${toString(aValue)}`
| IevTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
| IevModule(_) => `Module::${toString(aValue)}`
| IEvArray(_) => `Array::${toString(aValue)}`
| IEvArrayString(_) => `ArrayString::${toString(aValue)}`
| IEvBool(_) => `Bool::${toString(aValue)}`
| IEvCall(_) => `Call::${toString(aValue)}`
| IEvDistribution(_) => `Distribution::${toString(aValue)}`
| IEvLambda(_) => `Lambda::${toString(aValue)}`
| IEvNumber(_) => `Number::${toString(aValue)}`
| IEvRecord(_) => `Record::${toString(aValue)}`
| IEvString(_) => `String::${toString(aValue)}`
| IEvSymbol(_) => `Symbol::${toString(aValue)}`
| IEvDate(_) => `Date::${toString(aValue)}`
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
| IEvDeclaration(_) => `Declaration::${toString(aValue)}`
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
| IEvModule(_) => `Module::${toString(aValue)}`
}
let argsToString = (args: array<expressionValue>): string => {
@ -139,21 +139,21 @@ type functionDefinitionSignature =
let valueToValueType = value =>
switch value {
| IevArray(_) => EvtArray
| IevArrayString(_) => EvtArrayString
| IevBool(_) => EvtBool
| IevCall(_) => EvtCall
| IevDistribution(_) => EvtDistribution
| IevLambda(_) => EvtLambda
| IevNumber(_) => EvtNumber
| IevRecord(_) => EvtRecord
| IevString(_) => EvtString
| IevSymbol(_) => EvtSymbol
| IevDate(_) => EvtDate
| IevTimeDuration(_) => EvtTimeDuration
| IevDeclaration(_) => EvtDeclaration
| IevTypeIdentifier(_) => EvtTypeIdentifier
| IevModule(_) => EvtModule
| IEvArray(_) => EvtArray
| IEvArrayString(_) => EvtArrayString
| IEvBool(_) => EvtBool
| IEvCall(_) => EvtCall
| IEvDistribution(_) => EvtDistribution
| IEvLambda(_) => EvtLambda
| IEvNumber(_) => EvtNumber
| IEvRecord(_) => EvtRecord
| IEvString(_) => EvtString
| IEvSymbol(_) => EvtSymbol
| IEvDate(_) => EvtDate
| IEvTimeDuration(_) => EvtTimeDuration
| IEvDeclaration(_) => EvtDeclaration
| IEvTypeIdentifier(_) => EvtTypeIdentifier
| IEvModule(_) => EvtModule
}
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
@ -187,25 +187,25 @@ let functionCallSignatureToString = (functionCallSignature: functionCallSignatur
let rec toExternal = (iev: expressionValue): ExternalExpressionValue.expressionValue => {
switch iev {
| IevArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray
| IevArrayString(v) => EvArrayString(v)
| IevBool(v) => EvBool(v)
| IevCall(v) => EvCall(v)
| IevDistribution(v) => EvDistribution(v)
| IevLambda(v) => EvLambda(lambdaValueToExternal(v))
| IevNumber(v) => EvNumber(v)
| IevRecord(v) => v->mapToExternal->EvRecord
| IevString(v) => EvString(v)
| IevSymbol(v) => EvSymbol(v)
| IevDate(v) => EvDate(v)
| IevTimeDuration(v) => EvTimeDuration(v)
| IevDeclaration(v) => {
| IEvArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray
| IEvArrayString(v) => EvArrayString(v)
| IEvBool(v) => EvBool(v)
| IEvCall(v) => EvCall(v)
| IEvDistribution(v) => EvDistribution(v)
| IEvLambda(v) => EvLambda(lambdaValueToExternal(v))
| IEvNumber(v) => EvNumber(v)
| IEvRecord(v) => v->mapToExternal->EvRecord
| IEvString(v) => EvString(v)
| IEvSymbol(v) => EvSymbol(v)
| IEvDate(v) => EvDate(v)
| IEvTimeDuration(v) => EvTimeDuration(v)
| IEvDeclaration(v) => {
let fn = lambdaValueToExternal(v.fn)
let args = v.args
EvDeclaration({fn: fn, args: args})
}
| IevTypeIdentifier(v) => EvTypeIdentifier(v)
| IevModule(v) => v->nameSpaceToTypeScriptBindings->EvModule
| IEvTypeIdentifier(v) => EvTypeIdentifier(v)
| IEvModule(v) => v->nameSpaceToTypeScriptBindings->EvModule
}
}
and mapToExternal = v =>
@ -225,25 +225,25 @@ and nameSpaceToTypeScriptBindings = (
let rec toInternal = (ev: ExternalExpressionValue.expressionValue): expressionValue => {
switch ev {
| EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IevArray
| EvArrayString(v) => IevArrayString(v)
| EvBool(v) => IevBool(v)
| EvCall(v) => IevCall(v)
| EvDistribution(v) => IevDistribution(v)
| EvLambda(v) => IevLambda(lambdaValueToInternal(v))
| EvNumber(v) => IevNumber(v)
| EvRecord(v) => v->recordToInternal->IevRecord
| EvString(v) => IevString(v)
| EvSymbol(v) => IevSymbol(v)
| EvDate(v) => IevDate(v)
| EvTimeDuration(v) => IevTimeDuration(v)
| EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IEvArray
| EvArrayString(v) => IEvArrayString(v)
| EvBool(v) => IEvBool(v)
| EvCall(v) => IEvCall(v)
| EvDistribution(v) => IEvDistribution(v)
| EvLambda(v) => IEvLambda(lambdaValueToInternal(v))
| EvNumber(v) => IEvNumber(v)
| EvRecord(v) => v->recordToInternal->IEvRecord
| EvString(v) => IEvString(v)
| EvSymbol(v) => IEvSymbol(v)
| EvDate(v) => IEvDate(v)
| EvTimeDuration(v) => IEvTimeDuration(v)
| EvDeclaration(v) => {
let fn = lambdaValueToInternal(v.fn)
let args = v.args
IevDeclaration({fn: fn, args: args})
IEvDeclaration({fn: fn, args: args})
}
| EvTypeIdentifier(v) => IevTypeIdentifier(v)
| EvModule(v) => v->nameSpaceFromTypeScriptBindings->IevModule
| EvTypeIdentifier(v) => IEvTypeIdentifier(v)
| EvModule(v) => v->nameSpaceFromTypeScriptBindings->IEvModule
}
}
and recordToInternal = v =>

View File

@ -37,9 +37,9 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
| "fromUnit_G"
| "fromUnit_T"
| "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
}
}

View File

@ -16,7 +16,7 @@ let availableNumbers: array<(string, float)> = [
let mathBindings: Bindings.t =
availableNumbers
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IevNumber(v)))
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IEvNumber(v)))
->Bindings.fromArray
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>