diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Helpers.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Helpers.res index 05eb1b01..91bd5866 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Helpers.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Helpers.res @@ -15,8 +15,4 @@ let removeDefaultsInternal = (iev: InternalExpressionValue.t) => { } } -let removeDefaultsExternal = (ev: ExternalExpressionValue.t): ExternalExpressionValue.t => - ev->InternalExpressionValue.toInternal->removeDefaultsInternal->InternalExpressionValue.toExternal - let rRemoveDefaultsInternal = r => Belt.Result.map(r, removeDefaultsInternal) -let rRemoveDefaultsExternal = r => Belt.Result.map(r, removeDefaultsExternal) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res index d32457e6..34a21573 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res @@ -1,7 +1,7 @@ module ErrorValue = Reducer_ErrorValue module Expression = Reducer_Expression module ExpressionT = Reducer_Expression_T -module ExternalExpressionValue = ReducerInterface.ExternalExpressionValue +module InternalExpressionValue = ReducerInterface.InternalExpressionValue open Jest open Expect @@ -9,8 +9,8 @@ open Expect let unwrapRecord = rValue => rValue->Belt.Result.flatMap(value => switch value { - | ExternalExpressionValue.EvRecord(aRecord) => Ok(aRecord) - | _ => ErrorValue.RETodo("TODO: External bindings must be returned")->Error + | InternalExpressionValue.IEvRecord(aRecord) => Ok(aRecord) + | _ => ErrorValue.RETodo("TODO: Internal bindings must be returned")->Error } ) @@ -18,15 +18,15 @@ let expectParseToBe = (code: string, answer: string) => Expression.BackCompatible.parse(code)->ExpressionT.toStringResult->expect->toBe(answer) let expectEvalToBe = (code: string, answer: string) => - Expression.BackCompatible.evaluateStringAsExternal(code) - ->Reducer_Helpers.rRemoveDefaultsExternal - ->ExternalExpressionValue.toStringResult + Expression.BackCompatible.evaluateString(code) + ->Reducer_Helpers.rRemoveDefaultsInternal + ->InternalExpressionValue.toStringResult ->expect ->toBe(answer) let expectEvalError = (code: string) => - Expression.BackCompatible.evaluateStringAsExternal(code) - ->ExternalExpressionValue.toStringResult + Expression.BackCompatible.evaluateString(code) + ->InternalExpressionValue.toStringResult ->expect ->toMatch("Error\(") diff --git a/packages/squiggle-lang/__tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.res b/packages/squiggle-lang/__tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.res index dd23d994..693dffa5 100644 --- a/packages/squiggle-lang/__tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.res +++ b/packages/squiggle-lang/__tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.res @@ -3,8 +3,8 @@ open Expect open Reducer_TestHelpers let expectEvalToBeOk = (code: string) => - Reducer_Expression.BackCompatible.evaluateStringAsExternal(code) - ->Reducer_Helpers.rRemoveDefaultsExternal + Reducer_Expression.BackCompatible.evaluateString(code) + ->Reducer_Helpers.rRemoveDefaultsInternal ->E.R.isOk ->expect ->toBe(true) @@ -92,8 +92,8 @@ describe("FunctionRegistry Library", () => { ((fn, example)) => { let responseType = example - ->Reducer_Expression.BackCompatible.evaluateStringAsExternal - ->E.R2.fmap(ReducerInterface_InternalExpressionValue.externalValueToValueType) + ->Reducer_Expression.BackCompatible.evaluateString + ->E.R2.fmap(ReducerInterface_InternalExpressionValue.valueToValueType) let expectedOutputType = fn.output |> E.O.toExn("") expect(responseType)->toEqual(Ok(expectedOutputType)) }, diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res index 0583d676..2c06b9d7 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.res @@ -2,4 +2,4 @@ open ForTS__Types @genType let getKeyValuePairs = (v: squiggleValue_Module): array<(string, squiggleValue)> => - ReducerInterface_InternalExpressionValue.nameSpaceToKeyValueArray(v) + ReducerInterface_InternalExpressionValue.nameSpaceToKeyValuePairs(v) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res index 3daeb98d..0f1c2037 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res @@ -76,8 +76,8 @@ let emptyModule: t = NameSpace(emptyMap) let emptyBindings = emptyModule let emptyNameSpace = emptyModule -let fromTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceFromTypeScriptBindings -let toTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceToTypeScriptBindings +// let fromTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceFromTypeScriptBindings +// let toTypeScriptBindings = ReducerInterface_InternalExpressionValue.nameSpaceToTypeScriptBindings let toExpressionValue = (nameSpace: t): internalExpressionValue => IEvBindings(nameSpace) let fromExpressionValue = (aValue: internalExpressionValue): t => diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res index b262a327..d350ad74 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res @@ -125,15 +125,4 @@ module BackCompatible = { let evaluateString = (peggyCode: string): result => parse(peggyCode)->Result.flatMap(evaluate) - - let evaluateAsExternal = (expression: t): result => - { - let accessors = ProjectAccessorsT.identityAccessors - expression->reduceExpressionInProject(accessors.stdLib, accessors) - }->Result.map(InternalExpressionValue.toExternal) - - let evaluateStringAsExternal = (peggyCode: string): result< - ExternalExpressionValue.t, - errorValue, - > => parse(peggyCode)->Result.flatMap(evaluateAsExternal) } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res index a715054b..2f0dd7df 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res @@ -1,9 +1,9 @@ module ErrorValue = Reducer_ErrorValue module Extra_Array = Reducer_Extra_Array -type internalCode = ReducerInterface_ExternalExpressionValue.internalCode -type environment = ReducerInterface_ExternalExpressionValue.environment +type internalCode = Object +type environment = GenericDist.env -let defaultEnvironment = ReducerInterface_ExternalExpressionValue.defaultEnvironment +let defaultEnvironment: environment = DistributionOperation.defaultEnv type rec t = | IEvArray(array) // FIXME: Convert to MapInt @@ -38,29 +38,6 @@ type internalExpressionValue = t type functionCall = (string, array) -module Internal = { - module NameSpace = { - external castNameSpaceToHidden: nameSpace => ReducerInterface_ExternalExpressionValue.hiddenNameSpace = - "%identity" - external castHiddenToNameSpace: ReducerInterface_ExternalExpressionValue.hiddenNameSpace => nameSpace = - "%identity" - } - module Lambda = { - let toInternal = (v: ReducerInterface_ExternalExpressionValue.lambdaValue): lambdaValue => { - let p = v.parameters - let c = v.context->NameSpace.castHiddenToNameSpace - let b = v.body - {parameters: p, context: c, body: b} - } - and toExternal = (v: lambdaValue): ReducerInterface_ExternalExpressionValue.lambdaValue => { - let p = v.parameters - let c = v.context->NameSpace.castNameSpaceToHidden - let b = v.body - {parameters: p, context: c, body: b} - } - } -} - let rec toString = aValue => switch aValue { | IEvArray(anArray) => { @@ -147,7 +124,7 @@ let toStringResultOkless = (codeResult: result): strin let toStringResultRecord = x => switch x { - | Ok(a) => `Ok(${ReducerInterface_ExternalExpressionValue.toStringRecord(a)})` + | Ok(a) => `Ok(${toStringMap(a)})` | Error(m) => `Error(${ErrorValue.errorToString(m)})` } @@ -247,79 +224,18 @@ let functionCallSignatureToString = (functionCallSignature: functionCallSignatur `${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})` } -let rec toExternal = (iev: t): ReducerInterface_ExternalExpressionValue.t => { - switch iev { - | IEvArray(v) => v->Belt.Array.map(e => toExternal(e))->EvArray - | IEvArrayString(v) => EvArrayString(v) - | IEvBool(v) => EvBool(v) - | IEvCall(v) => EvCall(v) - | IEvDeclaration(v) => { - let fn = lambdaValueToExternal(v.fn) - let args = v.args - EvDeclaration({fn: fn, args: args}) - } - | IEvDistribution(v) => EvDistribution(v) - | IEvLambda(v) => EvLambda(lambdaValueToExternal(v)) - | IEvNumber(v) => EvNumber(v) - | IEvRecord(v) => v->mapToExternal->EvRecord - | IEvString(v) => EvString(v) - | IEvSymbol(v) => EvSymbol(v) - | IEvDate(v) => EvDate(v) - | IEvTimeDuration(v) => EvTimeDuration(v) - | IEvType(v) => v->mapToExternal->EvType - | IEvTypeIdentifier(v) => EvTypeIdentifier(v) - | IEvBindings(v) => v->nameSpaceToTypeScriptBindings->EvModule - | IEvVoid => EvVoid - } -} -and mapToExternal = v => - v->Belt.Map.String.map(e => toExternal(e))->Belt.Map.String.toArray->Js.Dict.fromArray -and lambdaValueToExternal = Internal.Lambda.toExternal -and nameSpaceToTypeScriptBindings = ( - nameSpace: nameSpace, -): 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: ReducerInterface_ExternalExpressionValue.t): t => { - switch ev { - | EvArray(v) => v->Belt.Array.map(e => toInternal(e))->IEvArray - | EvArrayString(v) => IEvArrayString(v) - | EvBool(v) => IEvBool(v) - | EvCall(v) => IEvCall(v) - | EvDate(v) => IEvDate(v) - | EvDeclaration(v) => { - let fn = lambdaValueToInternal(v.fn) - let args = v.args - IEvDeclaration({fn: fn, args: args}) - } - | EvDistribution(v) => IEvDistribution(v) - | EvLambda(v) => IEvLambda(lambdaValueToInternal(v)) - | EvModule(v) => v->nameSpaceFromTypeScriptBindings->IEvBindings - | EvNumber(v) => IEvNumber(v) - | EvRecord(v) => v->recordToInternal->IEvRecord - | EvString(v) => IEvString(v) - | EvSymbol(v) => IEvSymbol(v) - | EvTimeDuration(v) => IEvTimeDuration(v) - | EvType(v) => v->recordToInternal->IEvType - | EvTypeIdentifier(v) => IEvTypeIdentifier(v) - | EvVoid => IEvVoid - } -} -and recordToInternal = v => - v->Js.Dict.entries->Belt.Map.String.fromArray->Belt.Map.String.map(e => toInternal(e)) -and lambdaValueToInternal = Internal.Lambda.toInternal -and nameSpaceFromTypeScriptBindings = ( - r: ReducerInterface_ExternalExpressionValue.externalBindings, -): nameSpace => - r->Js.Dict.entries->Belt.Map.String.fromArray->Belt.Map.String.map(e => toInternal(e))->NameSpace - -let nameSpaceToKeyValueArray = (nameSpace: nameSpace): array<(string, t)> => { - let NameSpace(container) = nameSpace - container->Belt.Map.String.toArray -} - let arrayToValueArray = (arr: array): array => arr let recordToKeyValuePairs = (record: map): array<(string, t)> => record->Belt.Map.String.toArray + +// let nameSpaceToTypeScriptBindings = ( +// nameSpace: nameSpace, +// ) => { +// let NameSpace(container) = nameSpace +// Belt.Map.String.map(container, e => e->Belt.Map.String.toArray->Js.Dict.fromArray) +// } + +let nameSpaceToKeyValuePairs = (nameSpace: nameSpace): array<(string, t)> => { + let NameSpace(container) = nameSpace + container->Belt.Map.String.toArray +} diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res index 8beec882..a868eeb5 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res @@ -2,5 +2,3 @@ module Bindings = Reducer_Bindings let internalStdLib: Bindings.t = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings->SquiggleLibrary_Versions.makeBindings - -let externalStdLib = internalStdLib->Bindings.toTypeScriptBindings