From 17c3fe9dd8e77cd056d308fa4f3d1a9e0afcb09d Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Sat, 30 Jul 2022 16:58:45 +0200 Subject: [PATCH 1/2] hiddenNameSpace --- ...ducerInterface_ExternalExpressionValue.res | 5 ++- ...ducerInterface_InternalExpressionValue.res | 37 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res index a4d6e713..bf698735 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res @@ -7,6 +7,9 @@ module ErrorValue = Reducer_ErrorValue @genType.opaque type internalCode = Object +@genType.opaque +type hiddenNameSpace = Object + @genType type rec externalExpressionValue = | EvArray(array) @@ -30,7 +33,7 @@ and record = Js.Dict.t and externalBindings = record and lambdaValue = { parameters: array, - context: externalBindings, + context: hiddenNameSpace, body: internalCode, } and lambdaDeclaration = Declaration.declaration diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res index 3805d790..86718b64 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res @@ -37,6 +37,29 @@ type internalExpressionValue = t type functionCall = (string, array) +module Internal = { + module NameSpace = { + external castNameSpaceToHidden: nameSpace => ExternalExpressionValue.hiddenNameSpace = + "%identity" + external castHiddenToNameSpace: ExternalExpressionValue.hiddenNameSpace => nameSpace = + "%identity" + } + module Lambda = { + let toInternal = (v: 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): 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) => { @@ -244,12 +267,7 @@ let rec toExternal = (iev: t): ExternalExpressionValue.t => { } and mapToExternal = v => v->Belt.Map.String.map(e => toExternal(e))->Belt.Map.String.toArray->Js.Dict.fromArray -and lambdaValueToExternal = v => { - let p = v.parameters - let c = v.context->nameSpaceToTypeScriptBindings - let b = v.body - {parameters: p, context: c, body: b} -} +and lambdaValueToExternal = Internal.Lambda.toExternal and nameSpaceToTypeScriptBindings = ( nameSpace: nameSpace, ): ReducerInterface_ExternalExpressionValue.externalBindings => { @@ -284,12 +302,7 @@ let rec toInternal = (ev: ExternalExpressionValue.t): t => { } and recordToInternal = v => v->Js.Dict.entries->Belt.Map.String.fromArray->Belt.Map.String.map(e => toInternal(e)) -and lambdaValueToInternal = v => { - let p = v.parameters - let c = v.context->nameSpaceFromTypeScriptBindings - let b = v.body - {parameters: p, context: c, body: b} -} +and lambdaValueToInternal = Internal.Lambda.toInternal and nameSpaceFromTypeScriptBindings = ( r: ReducerInterface_ExternalExpressionValue.externalBindings, ): nameSpace => From 5d744fe2d06c293ea864ba636db1a880c09f9ad5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Sun, 31 Jul 2022 00:20:51 +0400 Subject: [PATCH 2/2] fix genType --- .../ReducerInterface_ExternalExpressionValue.res | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res index bf698735..d613ceb8 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExternalExpressionValue.res @@ -30,7 +30,6 @@ type rec externalExpressionValue = | EvType(record) | EvVoid and record = Js.Dict.t -and externalBindings = record and lambdaValue = { parameters: array, context: hiddenNameSpace, @@ -38,6 +37,9 @@ and lambdaValue = { } and lambdaDeclaration = Declaration.declaration +@genType +type externalBindings = record + @genType type t = externalExpressionValue