/* 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 */ module Extra_Array = Reducer_Extra_Array module ErrorValue = Reducer_ErrorValue @genType.opaque type internalCode = Object @genType type rec externalExpressionValue = | EvArray(array) | EvArrayString(array) | EvBool(bool) | EvCall(string) // External function call | EvDistribution(DistributionTypes.genericDist) | EvLambda(lambdaValue) | EvNumber(float) | EvRecord(record) | EvString(string) | EvSymbol(string) | EvDate(Js.Date.t) | EvTimeDuration(float) | EvDeclaration(lambdaDeclaration) | EvTypeIdentifier(string) | EvModule(record) | EvType(record) and record = Js.Dict.t and externalBindings = record and lambdaValue = { parameters: array, context: externalBindings, body: internalCode, } and lambdaDeclaration = Declaration.declaration @genType type t = externalExpressionValue type functionCall = (string, array) let rec toString = aValue => switch aValue { | EvArray(anArray) => { let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString `[${args}]` } | EvArrayString(anArray) => { let args = anArray->Js.Array2.toString `[${args}]` } | EvBool(aBool) => Js.String.make(aBool) | EvCall(fName) => `:${fName}` | EvDate(date) => DateTime.Date.toString(date) | EvDeclaration(d) => Declaration.toString(d, r => toString(EvLambda(r))) | EvDistribution(dist) => GenericDist.toString(dist) | EvLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)` | EvModule(m) => `@${m->toStringRecord}` | EvNumber(aNumber) => Js.String.make(aNumber) | EvRecord(aRecord) => aRecord->toStringRecord | EvString(aString) => `'${aString}'` | EvSymbol(aString) => `:${aString}` | EvTimeDuration(t) => DateTime.Duration.toString(t) | EvType(t) => `type${t->toStringRecord}` | EvTypeIdentifier(id) => `#${id}` } and toStringRecord = aRecord => { let pairs = aRecord ->Js.Dict.entries ->Js.Array2.map(((eachKey, eachValue)) => `${eachKey}: ${toString(eachValue)}`) ->Js.Array2.toString `{${pairs}}` } let argsToString = (args: array): string => { args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString } let toStringFunctionCall = ((fn, args)): string => `${fn}(${argsToString(args)})` let toStringResult = x => switch x { | Ok(a) => `Ok(${toString(a)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})` } @genType type environment = GenericDist.env @genType let defaultEnvironment: environment = DistributionOperation.defaultEnv