PR comments

This commit is contained in:
Umur Ozkul 2022-06-24 12:15:38 +02:00
parent 07d5c6d8b3
commit e192fe5790
29 changed files with 228 additions and 234 deletions

View File

@ -4,7 +4,7 @@ module ExternalExpressionValue = ReducerInterface.ExternalExpressionValue
module InternalExpressionValue = ReducerInterface.InternalExpressionValue module InternalExpressionValue = ReducerInterface.InternalExpressionValue
module Module = Reducer_Category_Module module Module = Reducer_Category_Module
let removeDefaultsInternal = (iev: InternalExpressionValue.expressionValue) => { let removeDefaultsInternal = (iev: InternalExpressionValue.t) => {
switch iev { switch iev {
| InternalExpressionValue.IEvModule(nameSpace) => | InternalExpressionValue.IEvModule(nameSpace) =>
Module.removeOther( Module.removeOther(
@ -15,9 +15,7 @@ let removeDefaultsInternal = (iev: InternalExpressionValue.expressionValue) => {
} }
} }
let removeDefaultsExternal = ( let removeDefaultsExternal = (ev: ExternalExpressionValue.t): ExternalExpressionValue.t =>
ev: ExternalExpressionValue.expressionValue,
): ExternalExpressionValue.expressionValue =>
ev->InternalExpressionValue.toInternal->removeDefaultsInternal->InternalExpressionValue.toExternal ev->InternalExpressionValue.toInternal->removeDefaultsInternal->InternalExpressionValue.toExternal
let rRemoveDefaultsInternal = r => Belt.Result.map(r, removeDefaultsInternal) let rRemoveDefaultsInternal = r => Belt.Result.map(r, removeDefaultsInternal)

View File

@ -12,7 +12,7 @@ module Module = Reducer_Category_Module
let testMacro_ = ( let testMacro_ = (
tester, tester,
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedCode: string, expectedCode: string,
) => { ) => {
@ -32,7 +32,7 @@ let testMacro_ = (
let testMacroEval_ = ( let testMacroEval_ = (
tester, tester,
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedValue: string, expectedValue: string,
) => { ) => {
@ -51,24 +51,24 @@ let testMacroEval_ = (
} }
let testMacro = ( let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedExpr: string, expectedExpr: string,
) => testMacro_(test, bindArray, expr, expectedExpr) ) => testMacro_(test, bindArray, expr, expectedExpr)
let testMacroEval = ( let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedValue: string, expectedValue: string,
) => testMacroEval_(test, bindArray, expr, expectedValue) ) => testMacroEval_(test, bindArray, expr, expectedValue)
module MySkip = { module MySkip = {
let testMacro = ( let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedExpr: string, expectedExpr: string,
) => testMacro_(Skip.test, bindArray, expr, expectedExpr) ) => testMacro_(Skip.test, bindArray, expr, expectedExpr)
let testMacroEval = ( let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedValue: string, expectedValue: string,
) => testMacroEval_(Skip.test, bindArray, expr, expectedValue) ) => testMacroEval_(Skip.test, bindArray, expr, expectedValue)
@ -76,12 +76,12 @@ module MySkip = {
module MyOnly = { module MyOnly = {
let testMacro = ( let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedExpr: string, expectedExpr: string,
) => testMacro_(Only.test, bindArray, expr, expectedExpr) ) => testMacro_(Only.test, bindArray, expr, expectedExpr)
let testMacroEval = ( let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>, bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression, expr: T.expression,
expectedValue: string, expectedValue: string,
) => testMacroEval_(Only.test, bindArray, expr, expectedValue) ) => testMacroEval_(Only.test, bindArray, expr, expectedValue)

View File

@ -1,4 +1,4 @@
type expressionValue = ReducerInterface_InternalExpressionValue.expressionValue type internalExpressionValue = ReducerInterface_InternalExpressionValue.t
/* /*
Function Registry "Type". A type, without any other information. Function Registry "Type". A type, without any other information.
@ -41,7 +41,7 @@ and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.g
type fnDefinition = { type fnDefinition = {
name: string, name: string,
inputs: array<frType>, inputs: array<frType>,
run: (array<frValue>, DistributionOperation.env) => result<expressionValue, string>, run: (array<frValue>, DistributionOperation.env) => result<internalExpressionValue, string>,
} }
type function = { type function = {
@ -73,7 +73,7 @@ module FRType = {
| FRTypeAny => `any` | FRTypeAny => `any`
} }
let rec toFrValue = (r: expressionValue): option<frValue> => let rec toFrValue = (r: internalExpressionValue): 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))
@ -89,7 +89,7 @@ module FRType = {
| _ => None | _ => None
} }
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> => let rec matchWithExpressionValue = (t: t, r: internalExpressionValue): 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))
@ -125,7 +125,7 @@ module FRType = {
| _ => None | _ => None
} }
let rec matchReverse = (e: frValue): expressionValue => let rec matchReverse = (e: frValue): internalExpressionValue =>
switch e { switch e {
| FRValueNumber(f) => IEvNumber(f) | FRValueNumber(f) => IEvNumber(f)
| FRValueDistOrNumber(FRValueNumber(n)) => IEvNumber(n) | FRValueDistOrNumber(FRValueNumber(n)) => IEvNumber(n)
@ -153,9 +153,10 @@ module FRType = {
| FRValueAny(f) => matchReverse(f) | FRValueAny(f) => matchReverse(f)
} }
let matchWithExpressionValueArray = (inputs: array<t>, args: array<expressionValue>): option< let matchWithExpressionValueArray = (
array<frValue>, inputs: array<t>,
> => { args: array<internalExpressionValue>,
): option<array<frValue>> => {
let isSameLength = E.A.length(inputs) == E.A.length(args) let isSameLength = E.A.length(inputs) == E.A.length(args)
if !isSameLength { if !isSameLength {
None None
@ -206,14 +207,14 @@ module Matcher = {
} }
module FnDefinition = { module FnDefinition = {
let matchAssumingSameName = (f: fnDefinition, args: array<expressionValue>) => { let matchAssumingSameName = (f: fnDefinition, args: array<internalExpressionValue>) => {
switch FRType.matchWithExpressionValueArray(f.inputs, args) { switch FRType.matchWithExpressionValueArray(f.inputs, args) {
| Some(_) => MatchSimple.FullMatch | Some(_) => MatchSimple.FullMatch
| None => MatchSimple.SameNameDifferentArguments | None => MatchSimple.SameNameDifferentArguments
} }
} }
let match = (f: fnDefinition, fnName: string, args: array<expressionValue>) => { let match = (f: fnDefinition, fnName: string, args: array<internalExpressionValue>) => {
if f.name !== fnName { if f.name !== fnName {
MatchSimple.DifferentName MatchSimple.DifferentName
} else { } else {
@ -226,7 +227,7 @@ module Matcher = {
type definitionId = int type definitionId = int
type match = Match.t<array<definitionId>, definitionId> type match = Match.t<array<definitionId>, definitionId>
let match = (f: function, fnName: string, args: array<expressionValue>): match => { let match = (f: function, fnName: string, args: array<internalExpressionValue>): match => {
let matchedDefinition = () => let matchedDefinition = () =>
E.A.getIndexBy(f.definitions, r => E.A.getIndexBy(f.definitions, r =>
MatchSimple.isFullMatch(FnDefinition.match(r, fnName, args)) MatchSimple.isFullMatch(FnDefinition.match(r, fnName, args))
@ -260,7 +261,7 @@ module Matcher = {
} }
module Registry = { module Registry = {
let _findExactMatches = (r: registry, fnName: string, args: array<expressionValue>) => { let _findExactMatches = (r: registry, fnName: string, args: array<internalExpressionValue>) => {
let functionMatchPairs = r->E.A2.fmap(l => (l, Function.match(l, fnName, args))) let functionMatchPairs = r->E.A2.fmap(l => (l, Function.match(l, fnName, args)))
let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match)) let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match))
fullMatch->E.O.bind(((fn, match)) => fullMatch->E.O.bind(((fn, match)) =>
@ -271,7 +272,7 @@ module Matcher = {
) )
} }
let _findNameMatches = (r: registry, fnName: string, args: array<expressionValue>) => { let _findNameMatches = (r: registry, fnName: string, args: array<internalExpressionValue>) => {
let functionMatchPairs = r->E.A2.fmap(l => (l, Function.match(l, fnName, args))) let functionMatchPairs = r->E.A2.fmap(l => (l, Function.match(l, fnName, args)))
let getNameMatches = let getNameMatches =
functionMatchPairs functionMatchPairs
@ -290,7 +291,7 @@ module Matcher = {
E.A.toNoneIfEmpty(matches) E.A.toNoneIfEmpty(matches)
} }
let findMatches = (r: registry, fnName: string, args: array<expressionValue>) => { let findMatches = (r: registry, fnName: string, args: array<internalExpressionValue>) => {
switch _findExactMatches(r, fnName, args) { switch _findExactMatches(r, fnName, args) {
| Some(r) => Match.FullMatch(r) | Some(r) => Match.FullMatch(r)
| None => | None =>
@ -318,7 +319,7 @@ module FnDefinition = {
t.name ++ `(${inputs})` t.name ++ `(${inputs})`
} }
let run = (t: t, args: array<expressionValue>, env: DistributionOperation.env) => { let run = (t: t, args: array<internalExpressionValue>, env: DistributionOperation.env) => {
let argValues = FRType.matchWithExpressionValueArray(t.inputs, args) let argValues = FRType.matchWithExpressionValueArray(t.inputs, args)
switch argValues { switch argValues {
| Some(values) => t.run(values, env) | Some(values) => t.run(values, env)
@ -372,7 +373,7 @@ module Registry = {
let matchAndRun = ( let matchAndRun = (
~registry: registry, ~registry: registry,
~fnName: string, ~fnName: string,
~args: array<expressionValue>, ~args: array<internalExpressionValue>,
~env: DistributionOperation.env, ~env: DistributionOperation.env,
) => { ) => {
let matchToDef = m => Matcher.Registry.matchToDef(registry, m) let matchToDef = m => Matcher.Registry.matchToDef(registry, m)

View File

@ -9,7 +9,7 @@ module Declaration = {
("inputs", FRTypeArray(FRTypeRecord([("min", FRTypeNumber), ("max", FRTypeNumber)]))), ("inputs", FRTypeArray(FRTypeRecord([("min", FRTypeNumber), ("max", FRTypeNumber)]))),
]) ])
let fromExpressionValue = (e: frValue): result<expressionValue, string> => { let fromExpressionValue = (e: frValue): result<internalExpressionValue, string> => {
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs([e]) { switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs([e]) {
| Ok([FRValueLambda(lambda), FRValueArray(inputs)]) => { | Ok([FRValueLambda(lambda), FRValueArray(inputs)]) => {
open FunctionRegistry_Helpers.Prepare open FunctionRegistry_Helpers.Prepare

View File

@ -1,13 +1,13 @@
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module Expression = Reducer_Expression module Expression = Reducer_Expression
module ExternalExpressionValue = ReducerInterface_ExpressionValue module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module Lambda = Reducer_Expression_Lambda module Lambda = Reducer_Expression_Lambda
type environment = ReducerInterface_InternalExpressionValue.environment type environment = ReducerInterface_InternalExpressionValue.environment
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type expressionValue = ExternalExpressionValue.expressionValue type expressionValue = ExternalExpressionValue.t
type externalBindings = ReducerInterface_ExpressionValue.externalBindings type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
type lambdaValue = ExternalExpressionValue.lambdaValue type lambdaValue = ExternalExpressionValue.lambdaValue
let evaluate = Expression.evaluate let evaluate = Expression.evaluate

View File

@ -2,27 +2,29 @@ module ErrorValue = Reducer_ErrorValue
module Expression = Reducer_Expression module Expression = Reducer_Expression
@genType @genType
type environment = ReducerInterface_ExpressionValue.environment type environment = ReducerInterface_ExternalExpressionValue.environment
@genType @genType
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
@genType @genType
type expressionValue = ReducerInterface_ExpressionValue.expressionValue type expressionValue = ReducerInterface_ExternalExpressionValue.t
@genType @genType
type externalBindings = ReducerInterface_ExpressionValue.externalBindings type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
@genType @genType
type lambdaValue = ReducerInterface_ExpressionValue.lambdaValue type lambdaValue = ReducerInterface_ExternalExpressionValue.lambdaValue
@genType @genType
let evaluateUsingOptions: ( let evaluateUsingOptions: (
~environment: option<QuriSquiggleLang.ReducerInterface_ExpressionValue.environment>, ~environment: option<QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment>,
~externalBindings: option<QuriSquiggleLang.ReducerInterface_ExpressionValue.externalBindings>, ~externalBindings: option<
QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.externalBindings,
>,
string, string,
) => result<expressionValue, errorValue> ) => result<expressionValue, errorValue>
@genType @genType
let evaluatePartialUsingExternalBindings: ( let evaluatePartialUsingExternalBindings: (
string, string,
QuriSquiggleLang.ReducerInterface_ExpressionValue.externalBindings, QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.externalBindings,
QuriSquiggleLang.ReducerInterface_ExpressionValue.environment, QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment,
) => result<externalBindings, errorValue> ) => result<externalBindings, errorValue>
@genType @genType
let evaluate: string => result<expressionValue, errorValue> let evaluate: string => result<expressionValue, errorValue>
@ -31,9 +33,9 @@ let parse: string => result<Expression.expression, errorValue>
@genType @genType
let foreignFunctionInterface: ( let foreignFunctionInterface: (
QuriSquiggleLang.ReducerInterface_ExpressionValue.lambdaValue, QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.lambdaValue,
array<QuriSquiggleLang.ReducerInterface_ExpressionValue.expressionValue>, array<QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.t>,
QuriSquiggleLang.ReducerInterface_ExpressionValue.environment, QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment,
) => result<expressionValue, errorValue> ) => result<expressionValue, errorValue>
@genType @genType

View File

@ -71,8 +71,8 @@ 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): internalExpressionValue => IEvModule(nameSpace)
let fromExpressionValue = (aValue: expressionValue): t => let fromExpressionValue = (aValue: internalExpressionValue): t =>
switch aValue { switch aValue {
| IEvModule(nameSpace) => nameSpace | IEvModule(nameSpace) => nameSpace
| _ => emptyModule | _ => emptyModule
@ -101,7 +101,7 @@ let removeOther = (nameSpace: t, other: t): t => {
} }
// -- Module definition // -- Module definition
let define = (nameSpace: t, identifier: string, ev: expressionValue): t => { let define = (nameSpace: t, identifier: string, ev: internalExpressionValue): t => {
let NameSpace(container) = nameSpace let NameSpace(container) = nameSpace
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
} }

View File

@ -14,8 +14,3 @@ let isOfResolvedType = (aType, aValue) => {
| _ => false | _ => false
} }
} }
// let compileTypeExpression = (typeExpression: string, bindings: ExpressionT.bindings, reducerFn: ExpressionT.reducerFn) => {
// statement = `type compiled=${typeExpression}`
// }

View File

@ -41,7 +41,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
->Ok ->Ok
} }
let arrayAtIndex = (aValueArray: array<expressionValue>, fIndex: float) => let arrayAtIndex = (aValueArray: array<internalExpressionValue>, fIndex: float) =>
switch Belt.Array.get(aValueArray, Belt.Int.fromFloat(fIndex)) { switch Belt.Array.get(aValueArray, Belt.Int.fromFloat(fIndex)) {
| Some(value) => value->Ok | Some(value) => value->Ok
| None => REArrayIndexNotFound("Array index not found", Belt.Int.fromFloat(fIndex))->Error | None => REArrayIndexNotFound("Array index not found", Belt.Int.fromFloat(fIndex))->Error
@ -53,7 +53,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
| None => RERecordPropertyNotFound("Module property not found", sIndex)->Error | None => RERecordPropertyNotFound("Module property not found", sIndex)->Error
} }
let recordAtIndex = (dict: Belt.Map.String.t<expressionValue>, sIndex) => let recordAtIndex = (dict: Belt.Map.String.t<internalExpressionValue>, sIndex) =>
switch Belt.Map.String.get(dict, sIndex) { switch Belt.Map.String.get(dict, sIndex) {
| Some(value) => value->Ok | Some(value) => value->Ok
| None => RERecordPropertyNotFound("Record property not found", sIndex)->Error | None => RERecordPropertyNotFound("Record property not found", sIndex)->Error
@ -69,24 +69,27 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
answer->IEvString->Ok answer->IEvString->Ok
} }
let inspect = (value: expressionValue) => { let inspect = (value: internalExpressionValue) => {
Js.log(value->toString) Js.log(value->toString)
value->Ok value->Ok
} }
let inspectLabel = (value: expressionValue, label: string) => { let inspectLabel = (value: internalExpressionValue, label: string) => {
Js.log(`${label}: ${value->toString}`) Js.log(`${label}: ${value->toString}`)
value->Ok value->Ok
} }
let doSetBindings = (bindings: nameSpace, symbol: string, value: expressionValue) => { let doSetBindings = (bindings: nameSpace, symbol: string, value: internalExpressionValue) => {
Module.set(bindings, symbol, value)->IEvModule->Ok Module.set(bindings, symbol, value)->IEvModule->Ok
} }
let doSetTypeAliasBindings = (bindings: nameSpace, symbol: string, value: expressionValue) => let doSetTypeAliasBindings = (
Module.setTypeAlias(bindings, symbol, value)->IEvModule->Ok bindings: nameSpace,
symbol: string,
value: internalExpressionValue,
) => Module.setTypeAlias(bindings, symbol, value)->IEvModule->Ok
let doSetTypeOfBindings = (bindings: nameSpace, symbol: string, value: expressionValue) => let doSetTypeOfBindings = (bindings: nameSpace, symbol: string, value: internalExpressionValue) =>
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
@ -296,7 +299,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
Reducer uses Result monad while reducing expressions Reducer uses Result monad while reducing expressions
*/ */
let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result< let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result<
expressionValue, internalExpressionValue,
errorValue, errorValue,
> => > =>
try { try {

View File

@ -7,16 +7,15 @@ module BindingsReplacer = Reducer_Expression_BindingsReplacer
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module ExpressionBuilder = Reducer_Expression_ExpressionBuilder module ExpressionBuilder = Reducer_Expression_ExpressionBuilder
module ExpressionT = Reducer_Expression_T module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module ExpressionWithContext = Reducer_ExpressionWithContext module ExpressionWithContext = Reducer_ExpressionWithContext
module Module = Reducer_Category_Module module Module = Reducer_Category_Module
module Result = Belt.Result module Result = Belt.Result
open Reducer_Expression_ExpressionBuilder open Reducer_Expression_ExpressionBuilder
type environment = ExpressionValue.environment type environment = InternalExpressionValue.environment
type errorValue = ErrorValue.errorValue type errorValue = ErrorValue.errorValue
type expression = ExpressionT.expression type expression = ExpressionT.expression
type expressionValue = ExpressionValue.expressionValue
type expressionWithContext = ExpressionWithContext.expressionWithContext type expressionWithContext = ExpressionWithContext.expressionWithContext
let dispatchMacroCall = ( let dispatchMacroCall = (
@ -137,11 +136,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) => { | InternalExpressionValue.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) => { | InternalExpressionValue.IEvBool(true) => {
let ifTrueBlock = eBlock(list{ifTrue}) let ifTrueBlock = eBlock(list{ifTrue})
ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok ExpressionWithContext.withContext(ifTrueBlock, bindings)->Ok
} }

View File

@ -13,9 +13,8 @@ module T = Reducer_Expression_T
type environment = InternalExpressionValue.environment type environment = InternalExpressionValue.environment
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type expression = T.expression type expression = T.expression
type expressionValue = InternalExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
type externalExpressionValue = ReducerInterface_ExpressionValue.expressionValue type externalExpressionValue = ReducerInterface_ExternalExpressionValue.t
type tmpExternalBindings = InternalExpressionValue.tmpExternalBindings
type t = expression type t = expression
/* /*
@ -28,7 +27,7 @@ let parse = (peggyCode: string): result<t, errorValue> =>
Recursively evaluate/reduce the expression (Lisp AST) Recursively evaluate/reduce the expression (Lisp AST)
*/ */
let rec reduceExpression = (expression: t, bindings: T.bindings, environment: environment): result< let rec reduceExpression = (expression: t, bindings: T.bindings, environment: environment): result<
expressionValue, internalExpressionValue,
'e, 'e,
> => { > => {
// Js.log(`reduce: ${T.toString(expression)} bindings: ${bindings->Bindings.toString}`) // Js.log(`reduce: ${T.toString(expression)} bindings: ${bindings->Bindings.toString}`)
@ -51,11 +50,11 @@ and reduceExpressionList = (
expressions: list<t>, expressions: list<t>,
bindings: T.bindings, bindings: T.bindings,
environment: environment, environment: environment,
): result<expressionValue, 'e> => { ): result<internalExpressionValue, 'e> => {
let racc: result<list<expressionValue>, 'e> = expressions->Belt.List.reduceReverse(Ok(list{}), ( let racc: result<
racc, list<internalExpressionValue>,
each: expression, 'e,
) => > = expressions->Belt.List.reduceReverse(Ok(list{}), (racc, each: expression) =>
racc->Result.flatMap(acc => { racc->Result.flatMap(acc => {
each each
->reduceExpression(bindings, environment) ->reduceExpression(bindings, environment)
@ -70,8 +69,8 @@ and reduceExpressionList = (
/* /*
After reducing each level of expression(Lisp AST), we have a value list to evaluate After reducing each level of expression(Lisp AST), we have a value list to evaluate
*/ */
and reduceValueList = (valueList: list<expressionValue>, environment): result< and reduceValueList = (valueList: list<internalExpressionValue>, environment): result<
expressionValue, internalExpressionValue,
'e, 'e,
> => > =>
switch valueList { switch valueList {
@ -108,18 +107,18 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
} }
let evalUsingBindingsExpression_ = (aExpression, bindings, environment): result< let evalUsingBindingsExpression_ = (aExpression, bindings, environment): result<
expressionValue, internalExpressionValue,
'e, 'e,
> => reduceExpression(aExpression, bindings, environment) > => reduceExpression(aExpression, bindings, environment)
let evaluateUsingOptions = ( let evaluateUsingOptions = (
~environment: option<ReducerInterface_ExpressionValue.environment>, ~environment: option<ReducerInterface_ExternalExpressionValue.environment>,
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>, ~externalBindings: option<ReducerInterface_ExternalExpressionValue.externalBindings>,
code: string, code: string,
): result<externalExpressionValue, errorValue> => { ): result<externalExpressionValue, errorValue> => {
let anEnvironment = Belt.Option.getWithDefault( let anEnvironment = Belt.Option.getWithDefault(
environment, environment,
ReducerInterface_ExpressionValue.defaultEnvironment, ReducerInterface_ExternalExpressionValue.defaultEnvironment,
) )
let mergedBindings: InternalExpressionValue.nameSpace = Module.merge( let mergedBindings: InternalExpressionValue.nameSpace = Module.merge(
@ -142,9 +141,9 @@ let evaluate = (code: string): result<externalExpressionValue, errorValue> => {
} }
let evaluatePartialUsingExternalBindings = ( let evaluatePartialUsingExternalBindings = (
code: string, code: string,
externalBindings: ReducerInterface_ExpressionValue.externalBindings, externalBindings: ReducerInterface_ExternalExpressionValue.externalBindings,
environment: ReducerInterface_ExpressionValue.environment, environment: ReducerInterface_ExternalExpressionValue.environment,
): result<ReducerInterface_ExpressionValue.externalBindings, errorValue> => { ): result<ReducerInterface_ExternalExpressionValue.externalBindings, errorValue> => {
let rAnswer = evaluateUsingOptions( let rAnswer = evaluateUsingOptions(
~environment=Some(environment), ~environment=Some(environment),
~externalBindings=Some(externalBindings), ~externalBindings=Some(externalBindings),

View File

@ -1,16 +1,16 @@
module BindingsReplacer = Reducer_Expression_BindingsReplacer module BindingsReplacer = Reducer_Expression_BindingsReplacer
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module ExpressionT = Reducer_Expression_T module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module Result = Belt.Result module Result = Belt.Result
module Module = Reducer_Category_Module module Module = Reducer_Category_Module
type bindings = ExpressionT.bindings type bindings = ExpressionT.bindings
type context = bindings type context = bindings
type environment = ExpressionValue.environment type environment = InternalExpressionValue.environment
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type expression = ExpressionT.expression type expression = ExpressionT.expression
type expressionValue = ExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
type reducerFn = ExpressionT.reducerFn type reducerFn = ExpressionT.reducerFn
type expressionWithContext = type expressionWithContext =
@ -22,7 +22,7 @@ let callReducer = (
bindings: bindings, bindings: bindings,
environment: environment, environment: environment,
reducer: reducerFn, reducer: reducerFn,
): result<expressionValue, errorValue> => { ): result<internalExpressionValue, errorValue> => {
switch expressionWithContext { switch expressionWithContext {
| ExpressionNoContext(expr) => | ExpressionNoContext(expr) =>
// Js.log(`callReducer: bindings ${Bindings.toString(bindings)} expr ${ExpressionT.toString(expr)}`) // Js.log(`callReducer: bindings ${Bindings.toString(bindings)} expr ${ExpressionT.toString(expr)}`)
@ -42,7 +42,7 @@ let toString = expressionWithContext =>
| ExpressionWithContext(expr, context) => | ExpressionWithContext(expr, context) =>
`${ExpressionT.toString(expr)} context: ${context `${ExpressionT.toString(expr)} context: ${context
->Module.toExpressionValue ->Module.toExpressionValue
->ExpressionValue.toString}` ->InternalExpressionValue.toString}`
} }
let toStringResult = rExpressionWithContext => let toStringResult = rExpressionWithContext =>

View File

@ -1,14 +1,13 @@
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module ExpressionT = Reducer_Expression_T module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module Result = Belt.Result module Result = Belt.Result
module Module = Reducer_Category_Module module Module = Reducer_Category_Module
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type expression = ExpressionT.expression type expression = ExpressionT.expression
type expressionValue = ExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
type tmpExternalBindings = ReducerInterface_InternalExpressionValue.tmpExternalBindings type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
let isMacroName = (fName: string): bool => fName->Js.String2.startsWith("$$") let isMacroName = (fName: string): bool => fName->Js.String2.startsWith("$$")
@ -41,14 +40,14 @@ and replaceSymbolsOnExpressionList = (bindings, list) => {
) )
racc->Result.map(acc => acc->ExpressionT.EList) racc->Result.map(acc => acc->ExpressionT.EList)
} }
and replaceSymbolOnValue = (bindings, evValue: expressionValue) => and replaceSymbolOnValue = (bindings, evValue: internalExpressionValue) =>
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: internalExpressionValue) =>
switch evValue { switch evValue {
| IEvCall(_) | IEvLambda(_) => evValue->Ok | IEvCall(_) | IEvLambda(_) => evValue->Ok
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error | _ => ErrorValue.RENotAFunction(InternalExpressionValue.toString(evValue))->Error
} }

View File

@ -1,7 +1,7 @@
module BBindingsReplacer = Reducer_Expression_BindingsReplacer module BBindingsReplacer = Reducer_Expression_BindingsReplacer
module BErrorValue = Reducer_ErrorValue module BErrorValue = Reducer_ErrorValue
module BExpressionT = Reducer_Expression_T module BExpressionT = Reducer_Expression_T
module BExpressionValue = ReducerInterface_InternalExpressionValue module BInternalExpressionValue = ReducerInterface_InternalExpressionValue
module BModule = Reducer_Category_Module module BModule = Reducer_Category_Module
type errorValue = BErrorValue.errorValue type errorValue = BErrorValue.errorValue
@ -12,16 +12,17 @@ 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->BInternalExpressionValue.IEvArray->BExpressionT.EValue
let eArrayString = anArray => anArray->BExpressionValue.IEvArrayString->BExpressionT.EValue let eArrayString = anArray => anArray->BInternalExpressionValue.IEvArrayString->BExpressionT.EValue
let eBindings = (anArray: array<(string, BExpressionValue.expressionValue)>) => let eBindings = (anArray: array<(string, BInternalExpressionValue.t)>) =>
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->BInternalExpressionValue.IEvBool->BExpressionT.EValue
let eCall = (name: string): expression => name->BExpressionValue.IEvCall->BExpressionT.EValue let eCall = (name: string): expression =>
name->BInternalExpressionValue.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
@ -30,10 +31,10 @@ let eFunction = (fName: string, lispArgs: list<expression>): expression => {
let eLambda = ( let eLambda = (
parameters: array<string>, parameters: array<string>,
context: BExpressionValue.nameSpace, context: BInternalExpressionValue.nameSpace,
expr: expression, expr: expression,
) => { ) => {
BExpressionValue.IEvLambda({ BInternalExpressionValue.IEvLambda({
parameters: parameters, parameters: parameters,
context: context, context: context,
body: NotFFI(expr)->castExpressionToInternalCode, body: NotFFI(expr)->castExpressionToInternalCode,
@ -42,27 +43,28 @@ 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({ BInternalExpressionValue.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->BInternalExpressionValue.IEvNumber->BExpressionT.EValue
let eRecord = aMap => aMap->BExpressionValue.IEvRecord->BExpressionT.EValue let eRecord = aMap => aMap->BInternalExpressionValue.IEvRecord->BExpressionT.EValue
let eString = aString => aString->BExpressionValue.IEvString->BExpressionT.EValue let eString = aString => aString->BInternalExpressionValue.IEvString->BExpressionT.EValue
let eSymbol = (name: string): expression => name->BExpressionValue.IEvSymbol->BExpressionT.EValue let eSymbol = (name: string): expression =>
name->BInternalExpressionValue.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: BInternalExpressionValue.nameSpace): expression =>
nameSpace->BExpressionValue.IEvModule->BExpressionT.EValue nameSpace->BInternalExpressionValue.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 +82,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->BInternalExpressionValue.IEvSymbol->BExpressionT.EValue
let eTypeIdentifier = (name: string): expression => let eTypeIdentifier = (name: string): expression =>
name->BExpressionValue.IEvTypeIdentifier->BExpressionT.EValue name->BInternalExpressionValue.IEvTypeIdentifier->BExpressionT.EValue

View File

@ -9,13 +9,16 @@ module Result = Belt.Result
type environment = ReducerInterface_InternalExpressionValue.environment type environment = ReducerInterface_InternalExpressionValue.environment
type expression = ExpressionT.expression type expression = ExpressionT.expression
type expressionOrFFI = ExpressionT.expressionOrFFI type expressionOrFFI = ExpressionT.expressionOrFFI
type expressionValue = ReducerInterface_InternalExpressionValue.expressionValue type internalExpressionValue = ReducerInterface_InternalExpressionValue.t
// type tmpExternalBindings = ReducerInterface_InternalExpressionValue.tmpExternalBindings // type tmpExternalBindings = ReducerInterface_InternalExpressionValue.tmpExternalBindings
type internalCode = ReducerInterface_InternalExpressionValue.internalCode type internalCode = ReducerInterface_InternalExpressionValue.internalCode
external castInternalCodeToExpression: internalCode => expressionOrFFI = "%identity" external castInternalCodeToExpression: internalCode => expressionOrFFI = "%identity"
let checkArity = (lambdaValue: ExpressionValue.lambdaValue, args: list<expressionValue>) => { let checkArity = (
lambdaValue: ExpressionValue.lambdaValue,
args: list<internalExpressionValue>,
) => {
let argsLength = Belt.List.length(args) let argsLength = Belt.List.length(args)
let parametersLength = Js.Array2.length(lambdaValue.parameters) let parametersLength = Js.Array2.length(lambdaValue.parameters)
if argsLength !== parametersLength { if argsLength !== parametersLength {
@ -25,7 +28,7 @@ let checkArity = (lambdaValue: ExpressionValue.lambdaValue, args: list<expressio
} }
} }
let checkIfReduced = (args: list<expressionValue>) => let checkIfReduced = (args: list<internalExpressionValue>) =>
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 {
@ -55,7 +58,7 @@ let applyParametersToLambda = (
args, args,
environment, environment,
reducer: ExpressionT.reducerFn, reducer: ExpressionT.reducerFn,
): result<expressionValue, 'e> => { ): result<internalExpressionValue, 'e> => {
checkArity(lambdaValue, args)->Result.flatMap(args => checkArity(lambdaValue, args)->Result.flatMap(args =>
checkIfReduced(args)->Result.flatMap(args => { checkIfReduced(args)->Result.flatMap(args => {
let exprOrFFI = castInternalCodeToExpression(lambdaValue.body) let exprOrFFI = castInternalCodeToExpression(lambdaValue.body)
@ -72,10 +75,10 @@ let doLambdaCall = (lambdaValue: ExpressionValue.lambdaValue, args, environment,
let foreignFunctionInterface = ( let foreignFunctionInterface = (
lambdaValue: ExpressionValue.lambdaValue, lambdaValue: ExpressionValue.lambdaValue,
argArray: array<expressionValue>, argArray: array<internalExpressionValue>,
environment: ExpressionValue.environment, environment: ExpressionValue.environment,
reducer: ExpressionT.reducerFn, reducer: ExpressionT.reducerFn,
): result<expressionValue, 'e> => { ): result<internalExpressionValue, 'e> => {
let args = argArray->Belt.List.fromArray let args = argArray->Belt.List.fromArray
applyParametersToLambda(lambdaValue, args, environment, reducer) applyParametersToLambda(lambdaValue, args, environment, reducer)
} }

View File

@ -1,11 +1,11 @@
module ExpressionT = Reducer_Expression_T module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module ExpressionWithContext = Reducer_ExpressionWithContext module ExpressionWithContext = Reducer_ExpressionWithContext
module Result = Belt.Result module Result = Belt.Result
type environment = ExpressionValue.environment type environment = InternalExpressionValue.environment
type expression = ExpressionT.expression type expression = ExpressionT.expression
type expressionValue = ExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
type expressionWithContext = ExpressionWithContext.expressionWithContext type expressionWithContext = ExpressionWithContext.expressionWithContext
let expandMacroCall = ( let expandMacroCall = (
@ -26,7 +26,7 @@ let doMacroCall = (
bindings: ExpressionT.bindings, bindings: ExpressionT.bindings,
environment: environment, environment: environment,
reduceExpression: ExpressionT.reducerFn, reduceExpression: ExpressionT.reducerFn,
): result<expressionValue, 'e> => ): result<internalExpressionValue, 'e> =>
expandMacroCall( expandMacroCall(
macroExpression, macroExpression,
bindings, bindings,

View File

@ -9,19 +9,19 @@
module Extra = Reducer_Extra module Extra = Reducer_Extra
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
type expressionValue = InternalExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
type environment = ReducerInterface_InternalExpressionValue.environment type environment = ReducerInterface_InternalExpressionValue.environment
type rec expression = type rec expression =
| EList(list<expression>) // A list to map-reduce | EList(list<expression>) // A list to map-reduce
| EValue(expressionValue) // Irreducible built-in value. Reducer should not know the internals. External libraries are responsible | EValue(internalExpressionValue) // Irreducible built-in value. Reducer should not know the internals. External libraries are responsible
and bindings = InternalExpressionValue.nameSpace and bindings = InternalExpressionValue.nameSpace
type reducerFn = ( type reducerFn = (
expression, expression,
bindings, bindings,
environment, environment,
) => result<expressionValue, Reducer_ErrorValue.errorValue> ) => result<internalExpressionValue, Reducer_ErrorValue.errorValue>
/* /*
Converts the expression to String Converts the expression to String
@ -67,9 +67,9 @@ let inspectResult = (r: result<expression, Reducer_ErrorValue.errorValue>): resu
} }
type ffiFn = ( type ffiFn = (
array<expressionValue>, array<internalExpressionValue>,
environment, environment,
) => result<expressionValue, Reducer_ErrorValue.errorValue> ) => result<internalExpressionValue, Reducer_ErrorValue.errorValue>
type expressionOrFFI = type expressionOrFFI =
| NotFFI(expression) | NotFFI(expression)

View File

@ -8,7 +8,7 @@ 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<internalExpressionValue, 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

View File

@ -17,7 +17,7 @@ let eval__: string => 'a = %raw(`function (expr) { return {value: Mathjs.evaluat
/* /*
Call MathJs evaluate and return as a variant Call MathJs evaluate and return as a variant
*/ */
let eval = (expr: string): result<expressionValue, errorValue> => { let eval = (expr: string): result<internalExpressionValue, errorValue> => {
try { try {
let answer = eval__(expr) let answer = eval__(expr)
answer["value"]->JavaScript.Gate.jsToIEv answer["value"]->JavaScript.Gate.jsToIEv

View File

@ -1,4 +1,4 @@
module ExternalExpressionValue = ReducerInterface_ExpressionValue module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module ExternalLibrary = ReducerInterface_ExternalLibrary module ExternalLibrary = ReducerInterface_ExternalLibrary
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module StdLib = ReducerInterface_StdLib module StdLib = ReducerInterface_StdLib

View File

@ -1,27 +1,27 @@
module EV = ReducerInterface_InternalExpressionValue module IEV = ReducerInterface_InternalExpressionValue
type expressionValue = EV.expressionValue type internalExpressionValue = IEV.t
let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option< let dispatch = (call: IEV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>, result<internalExpressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => { > => {
switch call { switch call {
| ("toString", [IEvDate(t)]) => EV.IEvString(DateTime.Date.toString(t))->Ok->Some | ("toString", [IEvDate(t)]) => IEV.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) => IEV.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)]) => IEV.IEvDate(DateTime.Date.fromFloat(f))->Ok->Some
| ("toNumber", [IEvDate(f)]) => EV.IEvNumber(DateTime.Date.toFloat(f))->Ok->Some | ("toNumber", [IEvDate(f)]) => IEV.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) => IEV.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 IEV.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 IEV.IEvDate(DateTime.Date.addDuration(d1, d2))->Ok->Some
| _ => None | _ => None
} }
} }

View File

@ -1,35 +1,36 @@
module EV = ReducerInterface_InternalExpressionValue module IEV = ReducerInterface_InternalExpressionValue
type expressionValue = EV.expressionValue type internalExpressionValue = IEV.t
let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option< let dispatch = (call: IEV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>, result<internalExpressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => { > => {
switch call { switch call {
| ("toString", [IEvTimeDuration(t)]) => EV.IEvString(DateTime.Duration.toString(t))->Ok->Some | ("toString", [IEvTimeDuration(t)]) => IEV.IEvString(DateTime.Duration.toString(t))->Ok->Some
| ("minutes", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some | ("minutes", [IEvNumber(f)]) => IEV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("fromUnit_minutes", [IEvNumber(f)]) => | ("fromUnit_minutes", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some IEV.IEvTimeDuration(DateTime.Duration.fromMinutes(f))->Ok->Some
| ("hours", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some | ("hours", [IEvNumber(f)]) => IEV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
| ("fromUnit_hours", [IEvNumber(f)]) => | ("fromUnit_hours", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some IEV.IEvTimeDuration(DateTime.Duration.fromHours(f))->Ok->Some
| ("days", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some | ("days", [IEvNumber(f)]) => IEV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
| ("fromUnit_days", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some | ("fromUnit_days", [IEvNumber(f)]) =>
| ("years", [IEvNumber(f)]) => EV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some IEV.IEvTimeDuration(DateTime.Duration.fromDays(f))->Ok->Some
| ("years", [IEvNumber(f)]) => IEV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
| ("fromUnit_years", [IEvNumber(f)]) => | ("fromUnit_years", [IEvNumber(f)]) =>
EV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some IEV.IEvTimeDuration(DateTime.Duration.fromYears(f))->Ok->Some
| ("toHours", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toHours(f))->Ok->Some | ("toHours", [IEvTimeDuration(f)]) => IEV.IEvNumber(DateTime.Duration.toHours(f))->Ok->Some
| ("toMinutes", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toMinutes(f))->Ok->Some | ("toMinutes", [IEvTimeDuration(f)]) => IEV.IEvNumber(DateTime.Duration.toMinutes(f))->Ok->Some
| ("toDays", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toDays(f))->Ok->Some | ("toDays", [IEvTimeDuration(f)]) => IEV.IEvNumber(DateTime.Duration.toDays(f))->Ok->Some
| ("toYears", [IEvTimeDuration(f)]) => EV.IEvNumber(DateTime.Duration.toYears(f))->Ok->Some | ("toYears", [IEvTimeDuration(f)]) => IEV.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 IEV.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 IEV.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 IEV.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 IEV.IEvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some
| ("divide", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) => EV.IEvNumber(d1 /. d2)->Ok->Some | ("divide", [IEvTimeDuration(d1), IEvTimeDuration(d2)]) => IEV.IEvNumber(d1 /. d2)->Ok->Some
| _ => None | _ => None
} }
} }

View File

@ -8,8 +8,8 @@ module ErrorValue = Reducer_ErrorValue
type internalCode = Object type internalCode = Object
@genType @genType
type rec expressionValue = type rec externalExpressionValue =
| EvArray(array<expressionValue>) | EvArray(array<externalExpressionValue>)
| EvArrayString(array<string>) | EvArrayString(array<string>)
| EvBool(bool) | EvBool(bool)
| EvCall(string) // External function call | EvCall(string) // External function call
@ -24,7 +24,7 @@ type rec expressionValue =
| EvDeclaration(lambdaDeclaration) | EvDeclaration(lambdaDeclaration)
| EvTypeIdentifier(string) | EvTypeIdentifier(string)
| EvModule(record) | EvModule(record)
and record = Js.Dict.t<expressionValue> and record = Js.Dict.t<externalExpressionValue>
and externalBindings = record and externalBindings = record
and lambdaValue = { and lambdaValue = {
parameters: array<string>, parameters: array<string>,
@ -33,7 +33,10 @@ and lambdaValue = {
} }
and lambdaDeclaration = Declaration.declaration<lambdaValue> and lambdaDeclaration = Declaration.declaration<lambdaValue>
type functionCall = (string, array<expressionValue>) @genType
type t = externalExpressionValue
type functionCall = (string, array<externalExpressionValue>)
let rec toString = aValue => let rec toString = aValue =>
switch aValue { switch aValue {
@ -68,7 +71,7 @@ and toStringRecord = aRecord => {
`{${pairs}}` `{${pairs}}`
} }
let argsToString = (args: array<expressionValue>): string => { let argsToString = (args: array<externalExpressionValue>): string => {
args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString
} }
@ -80,18 +83,6 @@ let toStringResult = x =>
| Error(m) => `Error(${ErrorValue.errorToString(m)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})`
} }
// let toStringResultOkless = (codeResult: result<expressionValue, ErrorValue.errorValue>): string =>
// switch codeResult {
// | Ok(a) => toString(a)
// | Error(m) => `Error(${ErrorValue.errorToString(m)})`
// }
// let toStringResultRecord = x =>
// switch x {
// | Ok(a) => `Ok(${toStringRecord(a)})`
// | Error(m) => `Error(${ErrorValue.errorToString(m)})`
// }
@genType @genType
type environment = DistributionOperation.env type environment = DistributionOperation.env

View File

@ -1,6 +1,6 @@
module ExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
type expressionValue = ExpressionValue.expressionValue type internalExpressionValue = InternalExpressionValue.t
// module Sample = { // module Sample = {
// // In real life real libraries should be somewhere else // // In real life real libraries should be somewhere else
@ -17,14 +17,14 @@ type expressionValue = ExpressionValue.expressionValue
// I expect that it's important to build this first, so it doesn't get recalculated for each tryRegistry() call. // I expect that it's important to build this first, so it doesn't get recalculated for each tryRegistry() call.
let registry = FunctionRegistry_Library.registry let registry = FunctionRegistry_Library.registry
let tryRegistry = ((fnName, args): ExpressionValue.functionCall, env) => { let tryRegistry = ((fnName, args): InternalExpressionValue.functionCall, env) => {
FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap( FunctionRegistry_Core.Registry.matchAndRun(~registry, ~fnName, ~args, ~env)->E.O2.fmap(
E.R2.errMap(_, s => Reducer_ErrorValue.RETodo(s)), E.R2.errMap(_, s => Reducer_ErrorValue.RETodo(s)),
) )
} }
let dispatch = (call: ExpressionValue.functionCall, environment, chain): result< let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): result<
expressionValue, internalExpressionValue,
'e, 'e,
> => { > => {
E.A.O.firstSomeFn([ E.A.O.firstSomeFn([

View File

@ -1,5 +1,5 @@
module ExpressionValue = ReducerInterface_InternalExpressionValue module IEV = ReducerInterface_InternalExpressionValue
type expressionValue = ExpressionValue.expressionValue type internalExpressionValue = IEV.t
module Helpers = { module Helpers = {
let arithmeticMap = r => let arithmeticMap = r =>
@ -18,7 +18,7 @@ module Helpers = {
| _ => #Multiply | _ => #Multiply
} }
let catchAndConvertTwoArgsToDists = (args: array<expressionValue>): option<( let catchAndConvertTwoArgsToDists = (args: array<internalExpressionValue>): option<(
DistributionTypes.genericDist, DistributionTypes.genericDist,
DistributionTypes.genericDist, DistributionTypes.genericDist,
)> => )> =>
@ -80,23 +80,28 @@ module Helpers = {
)->DistributionOperation.run(~env) )->DistributionOperation.run(~env)
} }
let parseNumber = (args: expressionValue): Belt.Result.t<float, string> => let parseNumber = (args: internalExpressionValue): 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")
} }
let parseNumberArray = (ags: array<expressionValue>): Belt.Result.t<array<float>, string> => let parseNumberArray = (ags: array<internalExpressionValue>): Belt.Result.t<
E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen array<float>,
string,
> => E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
let parseDist = (args: expressionValue): Belt.Result.t<DistributionTypes.genericDist, string> => let parseDist = (args: internalExpressionValue): 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")
} }
let parseDistributionArray = (ags: array<expressionValue>): Belt.Result.t< let parseDistributionArray = (ags: array<internalExpressionValue>): Belt.Result.t<
array<DistributionTypes.genericDist>, array<DistributionTypes.genericDist>,
string, string,
> => E.A.fmap(parseDist, ags) |> E.A.R.firstErrorOrOpen > => E.A.fmap(parseDist, ags) |> E.A.R.firstErrorOrOpen
@ -122,7 +127,7 @@ module Helpers = {
} }
let mixture = ( let mixture = (
args: array<expressionValue>, args: array<internalExpressionValue>,
~env: DistributionOperation.env, ~env: DistributionOperation.env,
): DistributionOperation.outputType => { ): DistributionOperation.outputType => {
let error = (err: string): DistributionOperation.outputType => let error = (err: string): DistributionOperation.outputType =>
@ -194,10 +199,9 @@ module SymbolicConstructors = {
} }
} }
let dispatchToGenericOutput = ( let dispatchToGenericOutput = (call: IEV.functionCall, env: DistributionOperation.env): option<
call: ExpressionValue.functionCall, DistributionOperation.outputType,
env: DistributionOperation.env, > => {
): 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)]) =>
@ -357,7 +361,7 @@ let dispatchToGenericOutput = (
} }
let genericOutputToReducerValue = (o: DistributionOperation.outputType): result< let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
expressionValue, internalExpressionValue,
Reducer_ErrorValue.errorValue, Reducer_ErrorValue.errorValue,
> => > =>
switch o { switch o {
@ -370,5 +374,5 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
| GenDistError(err) => Error(REDistributionError(err)) | GenDistError(err) => Error(REDistributionError(err))
} }
let dispatch = (call: ExpressionValue.functionCall, environment) => let dispatch = (call: IEV.functionCall, environment) =>
dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue) dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)

View File

@ -1,6 +1,4 @@
let dispatch: ( let dispatch: (
ReducerInterface_InternalExpressionValue.functionCall, ReducerInterface_InternalExpressionValue.functionCall,
ReducerInterface_ExpressionValue.environment, ReducerInterface_ExternalExpressionValue.environment,
) => option< ) => option<result<ReducerInterface_InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>
result<ReducerInterface_InternalExpressionValue.expressionValue, Reducer_ErrorValue.errorValue>,
>

View File

@ -1,13 +1,13 @@
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module ExternalExpressionValue = ReducerInterface_ExpressionValue module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module Extra_Array = Reducer_Extra_Array module Extra_Array = Reducer_Extra_Array
type internalCode = ExternalExpressionValue.internalCode type internalCode = ExternalExpressionValue.internalCode
type environment = ExternalExpressionValue.environment type environment = ExternalExpressionValue.environment
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
type rec expressionValue = type rec t =
| IEvArray(array<expressionValue>) // FIXME: Convert | IEvArray(array<t>) // 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
@ -15,16 +15,15 @@ type rec expressionValue =
| IEvDeclaration(lambdaDeclaration) | IEvDeclaration(lambdaDeclaration)
| IEvDistribution(DistributionTypes.genericDist) | IEvDistribution(DistributionTypes.genericDist)
| IEvLambda(lambdaValue) | IEvLambda(lambdaValue)
| IEvModule(nameSpace) // FIXME: Convert | IEvModule(nameSpace)
| 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<t>
and nameSpace = NameSpace(Belt.Map.String.t<expressionValue>) and nameSpace = NameSpace(Belt.Map.String.t<t>)
and tmpExternalBindings = Js.Dict.t<expressionValue> // FIXME: Remove
and lambdaValue = { and lambdaValue = {
parameters: array<string>, parameters: array<string>,
context: nameSpace, context: nameSpace,
@ -32,9 +31,9 @@ and lambdaValue = {
} }
and lambdaDeclaration = Declaration.declaration<lambdaValue> and lambdaDeclaration = Declaration.declaration<lambdaValue>
type t = expressionValue type internalExpressionValue = t
type functionCall = (string, array<expressionValue>) type functionCall = (string, array<t>)
let rec toString = aValue => let rec toString = aValue =>
switch aValue { switch aValue {
@ -92,7 +91,7 @@ let toStringWithType = aValue =>
| IEvModule(_) => `Module::${toString(aValue)}` | IEvModule(_) => `Module::${toString(aValue)}`
} }
let argsToString = (args: array<expressionValue>): string => { let argsToString = (args: array<t>): string => {
args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString
} }
@ -104,7 +103,7 @@ let toStringResult = x =>
| Error(m) => `Error(${ErrorValue.errorToString(m)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})`
} }
let toStringResultOkless = (codeResult: result<expressionValue, ErrorValue.errorValue>): string => let toStringResultOkless = (codeResult: result<t, ErrorValue.errorValue>): string =>
switch codeResult { switch codeResult {
| Ok(a) => toString(a) | Ok(a) => toString(a)
| Error(m) => `Error(${ErrorValue.errorToString(m)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})`
@ -116,7 +115,7 @@ let toStringResultRecord = x =>
| Error(m) => `Error(${ErrorValue.errorToString(m)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})`
} }
type expressionValueType = type internalExpressionValueType =
| EvtArray | EvtArray
| EvtArrayString | EvtArrayString
| EvtBool | EvtBool
@ -133,9 +132,9 @@ type expressionValueType =
| EvtTypeIdentifier | EvtTypeIdentifier
| EvtModule | EvtModule
type functionCallSignature = CallSignature(string, array<expressionValueType>) type functionCallSignature = CallSignature(string, array<internalExpressionValueType>)
type functionDefinitionSignature = type functionDefinitionSignature =
FunctionDefinitionSignature(functionCallSignature, expressionValueType) FunctionDefinitionSignature(functionCallSignature, internalExpressionValueType)
let valueToValueType = value => let valueToValueType = value =>
switch value { switch value {
@ -161,7 +160,7 @@ let functionCallToCallSignature = (functionCall: functionCall): functionCallSign
CallSignature(fn, args->Js.Array2.map(valueToValueType)) CallSignature(fn, args->Js.Array2.map(valueToValueType))
} }
let valueTypeToString = (valueType: expressionValueType): string => let valueTypeToString = (valueType: internalExpressionValueType): string =>
switch valueType { switch valueType {
| EvtArray => `Array` | EvtArray => `Array`
| EvtArrayString => `ArrayString` | EvtArrayString => `ArrayString`
@ -185,7 +184,7 @@ let functionCallSignatureToString = (functionCallSignature: functionCallSignatur
`${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})` `${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})`
} }
let rec toExternal = (iev: expressionValue): ExternalExpressionValue.expressionValue => { let rec toExternal = (iev: t): ExternalExpressionValue.t => {
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)
@ -218,12 +217,12 @@ and lambdaValueToExternal = v => {
} }
and nameSpaceToTypeScriptBindings = ( and nameSpaceToTypeScriptBindings = (
nameSpace: nameSpace, nameSpace: nameSpace,
): ReducerInterface_ExpressionValue.externalBindings => { ): ReducerInterface_ExternalExpressionValue.externalBindings => {
let NameSpace(container) = nameSpace let NameSpace(container) = nameSpace
Belt.Map.String.map(container, e => toExternal(e))->Belt.Map.String.toArray->Js.Dict.fromArray Belt.Map.String.map(container, e => toExternal(e))->Belt.Map.String.toArray->Js.Dict.fromArray
} }
let rec toInternal = (ev: ExternalExpressionValue.expressionValue): expressionValue => { let rec toInternal = (ev: ExternalExpressionValue.t): t => {
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)
@ -255,6 +254,6 @@ and lambdaValueToInternal = v => {
{parameters: p, context: c, body: b} {parameters: p, context: c, body: b}
} }
and nameSpaceFromTypeScriptBindings = ( and nameSpaceFromTypeScriptBindings = (
r: ReducerInterface_ExpressionValue.externalBindings, r: ReducerInterface_ExternalExpressionValue.externalBindings,
): nameSpace => ): nameSpace =>
r->Js.Dict.entries->Belt.Map.String.fromArray->Belt.Map.String.map(e => toInternal(e))->NameSpace r->Js.Dict.entries->Belt.Map.String.fromArray->Belt.Map.String.map(e => toInternal(e))->NameSpace

View File

@ -1,5 +1,5 @@
module EV = ReducerInterface_InternalExpressionValue module IEV = ReducerInterface_InternalExpressionValue
type expressionValue = EV.expressionValue type internalExpressionValue = IEV.t
module ScientificUnit = { module ScientificUnit = {
let nameToMultiplier = str => let nameToMultiplier = str =>
@ -24,8 +24,8 @@ module ScientificUnit = {
} }
} }
let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option< let dispatch = (call: IEV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>, result<internalExpressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => { > => {
switch call { switch call {
| ( | (
@ -39,7 +39,7 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
| "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 => IEV.IEvNumber(f *. multiplier)->Ok)
| _ => None | _ => None
} }
} }

View File

@ -47,10 +47,10 @@ let evaluatePartialUsingExternalBindings = Reducer.evaluatePartialUsingExternalB
type externalBindings = Reducer.externalBindings type externalBindings = Reducer.externalBindings
@genType @genType
type expressionValue = ReducerInterface_ExpressionValue.expressionValue type expressionValue = ReducerInterface_ExternalExpressionValue.t
@genType @genType
type recordEV = ReducerInterface_ExpressionValue.record type recordEV = ReducerInterface_ExternalExpressionValue.record
@genType @genType
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
@ -74,19 +74,19 @@ let errorValueToString = Reducer_ErrorValue.errorToString
let distributionErrorToString = DistributionTypes.Error.toString let distributionErrorToString = DistributionTypes.Error.toString
@genType @genType
type lambdaValue = ReducerInterface_ExpressionValue.lambdaValue type lambdaValue = ReducerInterface_ExternalExpressionValue.lambdaValue
@genType @genType
type lambdaDeclaration = ReducerInterface_ExpressionValue.lambdaDeclaration type lambdaDeclaration = ReducerInterface_ExternalExpressionValue.lambdaDeclaration
@genType @genType
let defaultSamplingEnv = DistributionOperation.defaultEnv let defaultSamplingEnv = DistributionOperation.defaultEnv
@genType @genType
type environment = ReducerInterface_ExpressionValue.environment type environment = ReducerInterface_ExternalExpressionValue.environment
@genType @genType
let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment let defaultEnvironment = ReducerInterface_ExternalExpressionValue.defaultEnvironment
@genType @genType
let foreignFunctionInterface = Reducer.foreignFunctionInterface let foreignFunctionInterface = Reducer.foreignFunctionInterface