2022-03-29 09:09:59 +00:00
|
|
|
/*
|
|
|
|
Irreducible values. Reducer does not know about those. Only used for external calls
|
|
|
|
This is a configuration to to make external calls of those types
|
|
|
|
*/
|
2022-03-30 10:53:36 +00:00
|
|
|
module Extra_Array = Reducer_Extra_Array
|
2022-03-29 09:09:59 +00:00
|
|
|
module ErrorValue = Reducer_ErrorValue
|
|
|
|
|
2022-04-24 23:09:51 +00:00
|
|
|
@genType.opaque
|
|
|
|
type internalCode = Object
|
|
|
|
|
2022-04-11 03:16:31 +00:00
|
|
|
@genType
|
2022-03-29 09:09:59 +00:00
|
|
|
type rec expressionValue =
|
2022-04-08 12:14:37 +00:00
|
|
|
| EvArray(array<expressionValue>)
|
2022-04-28 16:35:09 +00:00
|
|
|
| EvArrayString(array<string>)
|
2022-03-29 09:09:59 +00:00
|
|
|
| EvBool(bool)
|
2022-04-08 12:14:37 +00:00
|
|
|
| EvCall(string) // External function call
|
2022-04-22 20:27:17 +00:00
|
|
|
| EvDistribution(DistributionTypes.genericDist)
|
2022-05-02 10:10:31 +00:00
|
|
|
| EvLambda(lambdaValue)
|
2022-03-29 09:09:59 +00:00
|
|
|
| EvNumber(float)
|
2022-04-28 16:35:09 +00:00
|
|
|
| EvRecord(record)
|
2022-03-29 09:09:59 +00:00
|
|
|
| EvString(string)
|
|
|
|
| EvSymbol(string)
|
2022-04-28 16:35:09 +00:00
|
|
|
and record = Js.Dict.t<expressionValue>
|
2022-05-02 10:10:31 +00:00
|
|
|
and externalBindings = record
|
|
|
|
and lambdaValue = {
|
|
|
|
parameters: array<string>,
|
|
|
|
context: externalBindings,
|
|
|
|
body: internalCode,
|
|
|
|
}
|
2022-03-29 09:09:59 +00:00
|
|
|
|
2022-04-27 20:00:42 +00:00
|
|
|
@genType
|
|
|
|
let defaultExternalBindings: externalBindings = Js.Dict.empty()
|
|
|
|
|
2022-03-29 09:09:59 +00:00
|
|
|
type functionCall = (string, array<expressionValue>)
|
|
|
|
|
2022-03-30 10:53:36 +00:00
|
|
|
let rec toString = aValue =>
|
2022-03-29 09:09:59 +00:00
|
|
|
switch aValue {
|
2022-04-28 16:35:09 +00:00
|
|
|
| EvArray(anArray) => {
|
|
|
|
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
|
|
|
|
`[${args}]`
|
|
|
|
}
|
|
|
|
| EvArrayString(anArray) => {
|
|
|
|
let args = anArray->Js.Array2.toString
|
|
|
|
`[${args}]`
|
|
|
|
}
|
2022-03-29 09:09:59 +00:00
|
|
|
| EvBool(aBool) => Js.String.make(aBool)
|
2022-04-08 12:14:37 +00:00
|
|
|
| EvCall(fName) => `:${fName}`
|
2022-05-02 10:55:28 +00:00
|
|
|
| EvLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
|
2022-03-29 09:09:59 +00:00
|
|
|
| EvNumber(aNumber) => Js.String.make(aNumber)
|
|
|
|
| EvString(aString) => `'${aString}'`
|
|
|
|
| EvSymbol(aString) => `:${aString}`
|
2022-04-17 18:07:21 +00:00
|
|
|
| EvRecord(aRecord) => aRecord->toStringRecord
|
2022-04-08 12:14:37 +00:00
|
|
|
| EvDistribution(dist) => GenericDist.toString(dist)
|
2022-03-29 09:09:59 +00:00
|
|
|
}
|
2022-04-17 18:07:21 +00:00
|
|
|
and toStringRecord = aRecord => {
|
|
|
|
let pairs =
|
|
|
|
aRecord
|
|
|
|
->Js.Dict.entries
|
2022-04-28 16:35:09 +00:00
|
|
|
->Js.Array2.map(((eachKey, eachValue)) => `${eachKey}: ${toString(eachValue)}`)
|
|
|
|
->Js.Array2.toString
|
2022-04-17 18:07:21 +00:00
|
|
|
`{${pairs}}`
|
|
|
|
}
|
2022-03-29 09:09:59 +00:00
|
|
|
|
2022-03-30 10:53:36 +00:00
|
|
|
let toStringWithType = aValue =>
|
2022-03-29 09:09:59 +00:00
|
|
|
switch aValue {
|
2022-04-25 00:37:35 +00:00
|
|
|
| EvArray(_) => `Array::${toString(aValue)}`
|
2022-04-28 16:35:09 +00:00
|
|
|
| EvArrayString(_) => `ArrayString::${toString(aValue)}`
|
2022-03-30 10:53:36 +00:00
|
|
|
| EvBool(_) => `Bool::${toString(aValue)}`
|
2022-04-08 12:14:37 +00:00
|
|
|
| EvCall(_) => `Call::${toString(aValue)}`
|
2022-04-25 00:37:35 +00:00
|
|
|
| EvDistribution(_) => `Distribution::${toString(aValue)}`
|
2022-05-02 10:10:31 +00:00
|
|
|
| EvLambda(_) => `Lambda::${toString(aValue)}`
|
2022-03-30 10:53:36 +00:00
|
|
|
| EvNumber(_) => `Number::${toString(aValue)}`
|
2022-04-25 00:37:35 +00:00
|
|
|
| EvRecord(_) => `Record::${toString(aValue)}`
|
2022-03-30 10:53:36 +00:00
|
|
|
| EvString(_) => `String::${toString(aValue)}`
|
|
|
|
| EvSymbol(_) => `Symbol::${toString(aValue)}`
|
2022-03-29 09:09:59 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 10:53:36 +00:00
|
|
|
let argsToString = (args: array<expressionValue>): string => {
|
2022-04-28 16:35:09 +00:00
|
|
|
args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString
|
2022-03-29 09:09:59 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 10:53:36 +00:00
|
|
|
let toStringFunctionCall = ((fn, args)): string => `${fn}(${argsToString(args)})`
|
2022-03-29 09:09:59 +00:00
|
|
|
|
2022-03-30 10:53:36 +00:00
|
|
|
let toStringResult = x =>
|
2022-03-29 09:09:59 +00:00
|
|
|
switch x {
|
2022-03-30 10:53:36 +00:00
|
|
|
| Ok(a) => `Ok(${toString(a)})`
|
|
|
|
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
|
2022-03-29 09:09:59 +00:00
|
|
|
}
|
2022-04-17 18:07:21 +00:00
|
|
|
|
|
|
|
let toStringResultRecord = x =>
|
|
|
|
switch x {
|
|
|
|
| Ok(a) => `Ok(${toStringRecord(a)})`
|
|
|
|
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
|
|
|
|
}
|
2022-04-27 20:00:42 +00:00
|
|
|
|
|
|
|
@genType
|
2022-04-29 22:51:00 +00:00
|
|
|
type environment = DistributionOperation.env
|
|
|
|
|
2022-04-27 20:00:42 +00:00
|
|
|
@genType
|
2022-04-29 22:51:00 +00:00
|
|
|
let defaultEnvironment: environment = DistributionOperation.defaultEnv
|