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

View File

@ -12,7 +12,7 @@ module Module = Reducer_Category_Module
let testMacro_ = (
tester,
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedCode: string,
) => {
@ -32,7 +32,7 @@ let testMacro_ = (
let testMacroEval_ = (
tester,
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedValue: string,
) => {
@ -51,24 +51,24 @@ let testMacroEval_ = (
}
let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedExpr: string,
) => testMacro_(test, bindArray, expr, expectedExpr)
let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedValue: string,
) => testMacroEval_(test, bindArray, expr, expectedValue)
module MySkip = {
let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedExpr: string,
) => testMacro_(Skip.test, bindArray, expr, expectedExpr)
let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedValue: string,
) => testMacroEval_(Skip.test, bindArray, expr, expectedValue)
@ -76,12 +76,12 @@ module MySkip = {
module MyOnly = {
let testMacro = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedExpr: string,
) => testMacro_(Only.test, bindArray, expr, expectedExpr)
let testMacroEval = (
bindArray: array<(string, InternalExpressionValue.expressionValue)>,
bindArray: array<(string, InternalExpressionValue.t)>,
expr: T.expression,
expectedValue: string,
) => 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.
@ -41,7 +41,7 @@ and frValueDistOrNumber = FRValueNumber(float) | FRValueDist(DistributionTypes.g
type fnDefinition = {
name: string,
inputs: array<frType>,
run: (array<frValue>, DistributionOperation.env) => result<expressionValue, string>,
run: (array<frValue>, DistributionOperation.env) => result<internalExpressionValue, string>,
}
type function = {
@ -73,7 +73,7 @@ module FRType = {
| FRTypeAny => `any`
}
let rec toFrValue = (r: expressionValue): option<frValue> =>
let rec toFrValue = (r: internalExpressionValue): option<frValue> =>
switch r {
| IEvNumber(f) => Some(FRValueNumber(f))
| IEvString(f) => Some(FRValueString(f))
@ -89,7 +89,7 @@ module FRType = {
| _ => None
}
let rec matchWithExpressionValue = (t: t, r: expressionValue): option<frValue> =>
let rec matchWithExpressionValue = (t: t, r: internalExpressionValue): option<frValue> =>
switch (t, r) {
| (FRTypeAny, f) => toFrValue(f)
| (FRTypeString, IEvString(f)) => Some(FRValueString(f))
@ -125,7 +125,7 @@ module FRType = {
| _ => None
}
let rec matchReverse = (e: frValue): expressionValue =>
let rec matchReverse = (e: frValue): internalExpressionValue =>
switch e {
| FRValueNumber(f) => IEvNumber(f)
| FRValueDistOrNumber(FRValueNumber(n)) => IEvNumber(n)
@ -153,9 +153,10 @@ module FRType = {
| FRValueAny(f) => matchReverse(f)
}
let matchWithExpressionValueArray = (inputs: array<t>, args: array<expressionValue>): option<
array<frValue>,
> => {
let matchWithExpressionValueArray = (
inputs: array<t>,
args: array<internalExpressionValue>,
): option<array<frValue>> => {
let isSameLength = E.A.length(inputs) == E.A.length(args)
if !isSameLength {
None
@ -206,14 +207,14 @@ module Matcher = {
}
module FnDefinition = {
let matchAssumingSameName = (f: fnDefinition, args: array<expressionValue>) => {
let matchAssumingSameName = (f: fnDefinition, args: array<internalExpressionValue>) => {
switch FRType.matchWithExpressionValueArray(f.inputs, args) {
| Some(_) => MatchSimple.FullMatch
| 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 {
MatchSimple.DifferentName
} else {
@ -226,7 +227,7 @@ module Matcher = {
type definitionId = int
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 = () =>
E.A.getIndexBy(f.definitions, r =>
MatchSimple.isFullMatch(FnDefinition.match(r, fnName, args))
@ -260,7 +261,7 @@ module Matcher = {
}
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 fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(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 getNameMatches =
functionMatchPairs
@ -290,7 +291,7 @@ module Matcher = {
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) {
| Some(r) => Match.FullMatch(r)
| None =>
@ -318,7 +319,7 @@ module FnDefinition = {
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)
switch argValues {
| Some(values) => t.run(values, env)
@ -372,7 +373,7 @@ module Registry = {
let matchAndRun = (
~registry: registry,
~fnName: string,
~args: array<expressionValue>,
~args: array<internalExpressionValue>,
~env: DistributionOperation.env,
) => {
let matchToDef = m => Matcher.Registry.matchToDef(registry, m)

View File

@ -9,7 +9,7 @@ module Declaration = {
("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]) {
| Ok([FRValueLambda(lambda), FRValueArray(inputs)]) => {
open FunctionRegistry_Helpers.Prepare

View File

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

View File

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

View File

@ -71,8 +71,8 @@ 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 fromExpressionValue = (aValue: expressionValue): t =>
let toExpressionValue = (nameSpace: t): internalExpressionValue => IEvModule(nameSpace)
let fromExpressionValue = (aValue: internalExpressionValue): t =>
switch aValue {
| IEvModule(nameSpace) => nameSpace
| _ => emptyModule
@ -101,7 +101,7 @@ let removeOther = (nameSpace: t, other: t): t => {
}
// -- Module definition
let define = (nameSpace: t, identifier: string, ev: expressionValue): t => {
let define = (nameSpace: t, identifier: string, ev: internalExpressionValue): t => {
let NameSpace(container) = nameSpace
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
}
}
// 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
}
let arrayAtIndex = (aValueArray: array<expressionValue>, fIndex: float) =>
let arrayAtIndex = (aValueArray: array<internalExpressionValue>, fIndex: float) =>
switch Belt.Array.get(aValueArray, Belt.Int.fromFloat(fIndex)) {
| Some(value) => value->Ok
| 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
}
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) {
| Some(value) => value->Ok
| None => RERecordPropertyNotFound("Record property not found", sIndex)->Error
@ -69,24 +69,27 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
answer->IEvString->Ok
}
let inspect = (value: expressionValue) => {
let inspect = (value: internalExpressionValue) => {
Js.log(value->toString)
value->Ok
}
let inspectLabel = (value: expressionValue, label: string) => {
let inspectLabel = (value: internalExpressionValue, label: string) => {
Js.log(`${label}: ${value->toString}`)
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
}
let doSetTypeAliasBindings = (bindings: nameSpace, symbol: string, value: expressionValue) =>
Module.setTypeAlias(bindings, symbol, value)->IEvModule->Ok
let doSetTypeAliasBindings = (
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
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
*/
let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result<
expressionValue,
internalExpressionValue,
errorValue,
> =>
try {

View File

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

View File

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

View File

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

View File

@ -1,14 +1,13 @@
module ErrorValue = Reducer_ErrorValue
module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface_InternalExpressionValue
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module Result = Belt.Result
module Module = Reducer_Category_Module
type errorValue = Reducer_ErrorValue.errorValue
type expression = ExpressionT.expression
type expressionValue = ExpressionValue.expressionValue
type tmpExternalBindings = ReducerInterface_InternalExpressionValue.tmpExternalBindings
type externalBindings = ReducerInterface_ExpressionValue.externalBindings
type internalExpressionValue = InternalExpressionValue.t
type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
let isMacroName = (fName: string): bool => fName->Js.String2.startsWith("$$")
@ -41,14 +40,14 @@ and replaceSymbolsOnExpressionList = (bindings, list) => {
)
racc->Result.map(acc => acc->ExpressionT.EList)
}
and replaceSymbolOnValue = (bindings, evValue: expressionValue) =>
and replaceSymbolOnValue = (bindings, evValue: internalExpressionValue) =>
switch evValue {
| IEvSymbol(symbol) => Module.getWithDefault(bindings, symbol, evValue)->Ok
| IEvCall(symbol) => Module.getWithDefault(bindings, symbol, evValue)->checkIfCallable
| _ => evValue->Ok
}
and checkIfCallable = (evValue: expressionValue) =>
and checkIfCallable = (evValue: internalExpressionValue) =>
switch evValue {
| 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 BErrorValue = Reducer_ErrorValue
module BExpressionT = Reducer_Expression_T
module BExpressionValue = ReducerInterface_InternalExpressionValue
module BInternalExpressionValue = ReducerInterface_InternalExpressionValue
module BModule = Reducer_Category_Module
type errorValue = BErrorValue.errorValue
@ -12,16 +12,17 @@ type internalCode = ReducerInterface_InternalExpressionValue.internalCode
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
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 fn = fName->eCall
@ -30,10 +31,10 @@ let eFunction = (fName: string, lispArgs: list<expression>): expression => {
let eLambda = (
parameters: array<string>,
context: BExpressionValue.nameSpace,
context: BInternalExpressionValue.nameSpace,
expr: expression,
) => {
BExpressionValue.IEvLambda({
BInternalExpressionValue.IEvLambda({
parameters: parameters,
context: context,
body: NotFFI(expr)->castExpressionToInternalCode,
@ -42,27 +43,28 @@ let eLambda = (
let eLambdaFFI = (parameters: array<string>, ffiFn: ffiFn) => {
let context = BModule.emptyModule
BExpressionValue.IEvLambda({
BInternalExpressionValue.IEvLambda({
parameters: parameters,
context: context,
body: FFI(ffiFn)->castExpressionToInternalCode,
})->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 eBlock = (exprs: list<expression>): expression => eFunction("$$_block_$$", exprs)
let eModule = (nameSpace: BExpressionValue.nameSpace): expression =>
nameSpace->BExpressionValue.IEvModule->BExpressionT.EValue
let eModule = (nameSpace: BInternalExpressionValue.nameSpace): expression =>
nameSpace->BInternalExpressionValue.IEvModule->BExpressionT.EValue
let eLetStatement = (symbol: string, valueExpression: expression): expression =>
eFunction("$_let_$", list{eSymbol(symbol), valueExpression})
@ -80,7 +82,7 @@ let eBindExpressionDefault = (expression: expression): expression =>
eFunction("$$_bindExpression_$$", list{expression})
let eIdentifier = (name: string): expression =>
name->BExpressionValue.IEvSymbol->BExpressionT.EValue
name->BInternalExpressionValue.IEvSymbol->BExpressionT.EValue
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 expression = ExpressionT.expression
type expressionOrFFI = ExpressionT.expressionOrFFI
type expressionValue = ReducerInterface_InternalExpressionValue.expressionValue
type internalExpressionValue = ReducerInterface_InternalExpressionValue.t
// type tmpExternalBindings = ReducerInterface_InternalExpressionValue.tmpExternalBindings
type internalCode = ReducerInterface_InternalExpressionValue.internalCode
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 parametersLength = Js.Array2.length(lambdaValue.parameters)
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) =>
rAcc->Result.flatMap(acc =>
switch arg {
@ -55,7 +58,7 @@ let applyParametersToLambda = (
args,
environment,
reducer: ExpressionT.reducerFn,
): result<expressionValue, 'e> => {
): result<internalExpressionValue, 'e> => {
checkArity(lambdaValue, args)->Result.flatMap(args =>
checkIfReduced(args)->Result.flatMap(args => {
let exprOrFFI = castInternalCodeToExpression(lambdaValue.body)
@ -72,10 +75,10 @@ let doLambdaCall = (lambdaValue: ExpressionValue.lambdaValue, args, environment,
let foreignFunctionInterface = (
lambdaValue: ExpressionValue.lambdaValue,
argArray: array<expressionValue>,
argArray: array<internalExpressionValue>,
environment: ExpressionValue.environment,
reducer: ExpressionT.reducerFn,
): result<expressionValue, 'e> => {
): result<internalExpressionValue, 'e> => {
let args = argArray->Belt.List.fromArray
applyParametersToLambda(lambdaValue, args, environment, reducer)
}

View File

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

View File

@ -9,19 +9,19 @@
module Extra = Reducer_Extra
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
type expressionValue = InternalExpressionValue.expressionValue
type internalExpressionValue = InternalExpressionValue.t
type environment = ReducerInterface_InternalExpressionValue.environment
type rec expression =
| 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
type reducerFn = (
expression,
bindings,
environment,
) => result<expressionValue, Reducer_ErrorValue.errorValue>
) => result<internalExpressionValue, Reducer_ErrorValue.errorValue>
/*
Converts the expression to String
@ -67,9 +67,9 @@ let inspectResult = (r: result<expression, Reducer_ErrorValue.errorValue>): resu
}
type ffiFn = (
array<expressionValue>,
array<internalExpressionValue>,
environment,
) => result<expressionValue, Reducer_ErrorValue.errorValue>
) => result<internalExpressionValue, Reducer_ErrorValue.errorValue>
type expressionOrFFI =
| 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
*/
let jsToIEv = (jsValue): result<expressionValue, errorValue> =>
let jsToIEv = (jsValue): result<internalExpressionValue, errorValue> =>
switch Js.typeof(jsValue) {
| "boolean" => jsValue->castBool->IEvBool->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
*/
let eval = (expr: string): result<expressionValue, errorValue> => {
let eval = (expr: string): result<internalExpressionValue, errorValue> => {
try {
let answer = eval__(expr)
answer["value"]->JavaScript.Gate.jsToIEv

View File

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

View File

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

View File

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

View File

@ -8,8 +8,8 @@ module ErrorValue = Reducer_ErrorValue
type internalCode = Object
@genType
type rec expressionValue =
| EvArray(array<expressionValue>)
type rec externalExpressionValue =
| EvArray(array<externalExpressionValue>)
| EvArrayString(array<string>)
| EvBool(bool)
| EvCall(string) // External function call
@ -24,7 +24,7 @@ type rec expressionValue =
| EvDeclaration(lambdaDeclaration)
| EvTypeIdentifier(string)
| EvModule(record)
and record = Js.Dict.t<expressionValue>
and record = Js.Dict.t<externalExpressionValue>
and externalBindings = record
and lambdaValue = {
parameters: array<string>,
@ -33,7 +33,10 @@ and lambdaValue = {
}
and lambdaDeclaration = Declaration.declaration<lambdaValue>
type functionCall = (string, array<expressionValue>)
@genType
type t = externalExpressionValue
type functionCall = (string, array<externalExpressionValue>)
let rec toString = aValue =>
switch aValue {
@ -68,7 +71,7 @@ and toStringRecord = aRecord => {
`{${pairs}}`
}
let argsToString = (args: array<expressionValue>): string => {
let argsToString = (args: array<externalExpressionValue>): string => {
args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString
}
@ -80,18 +83,6 @@ let toStringResult = x =>
| 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
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 = {
// // 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.
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(
E.R2.errMap(_, s => Reducer_ErrorValue.RETodo(s)),
)
}
let dispatch = (call: ExpressionValue.functionCall, environment, chain): result<
expressionValue,
let dispatch = (call: InternalExpressionValue.functionCall, environment, chain): result<
internalExpressionValue,
'e,
> => {
E.A.O.firstSomeFn([

View File

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

View File

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

View File

@ -1,13 +1,13 @@
module ErrorValue = Reducer_ErrorValue
module ExternalExpressionValue = ReducerInterface_ExpressionValue
module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module Extra_Array = Reducer_Extra_Array
type internalCode = ExternalExpressionValue.internalCode
type environment = ExternalExpressionValue.environment
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
type rec expressionValue =
| IEvArray(array<expressionValue>) // FIXME: Convert
type rec t =
| IEvArray(array<t>) // FIXME: Convert
| IEvArrayString(array<string>) // FIXME: Convert
| IEvBool(bool)
| IEvCall(string) // External function call
@ -15,16 +15,15 @@ type rec expressionValue =
| IEvDeclaration(lambdaDeclaration)
| IEvDistribution(DistributionTypes.genericDist)
| IEvLambda(lambdaValue)
| IEvModule(nameSpace) // FIXME: Convert
| IEvModule(nameSpace)
| 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
and map = Belt.Map.String.t<t>
and nameSpace = NameSpace(Belt.Map.String.t<t>)
and lambdaValue = {
parameters: array<string>,
context: nameSpace,
@ -32,9 +31,9 @@ and 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 =>
switch aValue {
@ -92,7 +91,7 @@ let toStringWithType = 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
}
@ -104,7 +103,7 @@ let toStringResult = x =>
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
}
let toStringResultOkless = (codeResult: result<expressionValue, ErrorValue.errorValue>): string =>
let toStringResultOkless = (codeResult: result<t, ErrorValue.errorValue>): string =>
switch codeResult {
| Ok(a) => toString(a)
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
@ -116,7 +115,7 @@ let toStringResultRecord = x =>
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
}
type expressionValueType =
type internalExpressionValueType =
| EvtArray
| EvtArrayString
| EvtBool
@ -133,9 +132,9 @@ type expressionValueType =
| EvtTypeIdentifier
| EvtModule
type functionCallSignature = CallSignature(string, array<expressionValueType>)
type functionCallSignature = CallSignature(string, array<internalExpressionValueType>)
type functionDefinitionSignature =
FunctionDefinitionSignature(functionCallSignature, expressionValueType)
FunctionDefinitionSignature(functionCallSignature, internalExpressionValueType)
let valueToValueType = value =>
switch value {
@ -161,7 +160,7 @@ let functionCallToCallSignature = (functionCall: functionCall): functionCallSign
CallSignature(fn, args->Js.Array2.map(valueToValueType))
}
let valueTypeToString = (valueType: expressionValueType): string =>
let valueTypeToString = (valueType: internalExpressionValueType): string =>
switch valueType {
| EvtArray => `Array`
| EvtArrayString => `ArrayString`
@ -185,7 +184,7 @@ let functionCallSignatureToString = (functionCallSignature: functionCallSignatur
`${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 {
| IEvArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray
| IEvArrayString(v) => EvArrayString(v)
@ -218,12 +217,12 @@ and lambdaValueToExternal = v => {
}
and nameSpaceToTypeScriptBindings = (
nameSpace: nameSpace,
): ReducerInterface_ExpressionValue.externalBindings => {
): ReducerInterface_ExternalExpressionValue.externalBindings => {
let NameSpace(container) = nameSpace
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 {
| EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IEvArray
| EvArrayString(v) => IEvArrayString(v)
@ -255,6 +254,6 @@ and lambdaValueToInternal = v => {
{parameters: p, context: c, body: b}
}
and nameSpaceFromTypeScriptBindings = (
r: ReducerInterface_ExpressionValue.externalBindings,
r: ReducerInterface_ExternalExpressionValue.externalBindings,
): 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
type expressionValue = EV.expressionValue
module IEV = ReducerInterface_InternalExpressionValue
type internalExpressionValue = IEV.t
module ScientificUnit = {
let nameToMultiplier = str =>
@ -24,8 +24,8 @@ module ScientificUnit = {
}
}
let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
result<expressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
let dispatch = (call: IEV.functionCall, _: DistributionOperation.env): option<
result<internalExpressionValue, QuriSquiggleLang.Reducer_ErrorValue.errorValue>,
> => {
switch call {
| (
@ -39,7 +39,7 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option<
| "fromUnit_P") as op,
[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
}
}

View File

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