From 05ce6d2872cf5c51d8411dfc953001fba850b89c Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Fri, 19 Aug 2022 23:01:38 +0200 Subject: [PATCH] Comment opaue type violations --- .../squiggle-lang/src/js/rescript_interop.ts | 281 +++++++++--------- 1 file changed, 142 insertions(+), 139 deletions(-) diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index 3dca8165..0495c5f3 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -17,68 +17,69 @@ import { tagged, tag } from "./types"; // This file is here to compensate for genType not fully recursively converting types // Raw rescript types. -export type rescriptExport = - | 0 // EvVoid - | { - TAG: 0; // EvArray - _0: rescriptExport[]; - } - | { - TAG: 1; // EvString - _0: string[]; - } - | { - TAG: 2; // EvBool - _0: boolean; - } - | { - TAG: 3; // EvCall - _0: string; - } - | { - TAG: 4; // EvDistribution - _0: rescriptDist; - } - | { - TAG: 5; // EvLambda - _0: lambdaValue; - } - | { - TAG: 6; // EvNumber - _0: number; - } - | { - TAG: 7; // EvRecord - _0: { [key: string]: rescriptExport }; - } - | { - TAG: 8; // EvString - _0: string; - } - | { - TAG: 9; // EvSymbol - _0: string; - } - | { - TAG: 10; // EvDate - _0: Date; - } - | { - TAG: 11; // EvTimeDuration - _0: number; - } - | { - TAG: 12; // EvDeclaration - _0: rescriptLambdaDeclaration; - } - | { - TAG: 13; // EvTypeIdentifier - _0: string; - } - | { - TAG: 14; // EvModule - _0: { [key: string]: rescriptExport }; - }; +// Umur: Rescript expression values are opaque! +// export type rescriptExport = +// | 0 // EvVoid +// | { +// TAG: 0; // EvArray +// _0: rescriptExport[]; +// } +// | { +// TAG: 1; // EvString +// _0: string[]; +// } +// | { +// TAG: 2; // EvBool +// _0: boolean; +// } +// | { +// TAG: 3; // EvCall +// _0: string; +// } +// | { +// TAG: 4; // EvDistribution +// _0: rescriptDist; +// } +// | { +// TAG: 5; // EvLambda +// _0: lambdaValue; +// } +// | { +// TAG: 6; // EvNumber +// _0: number; +// } +// | { +// TAG: 7; // EvRecord +// _0: { [key: string]: rescriptExport }; +// } +// | { +// TAG: 8; // EvString +// _0: string; +// } +// | { +// TAG: 9; // EvSymbol +// _0: string; +// } +// | { +// TAG: 10; // EvDate +// _0: Date; +// } +// | { +// TAG: 11; // EvTimeDuration +// _0: number; +// } +// | { +// TAG: 12; // EvDeclaration +// _0: rescriptLambdaDeclaration; +// } +// | { +// TAG: 13; // EvTypeIdentifier +// _0: string; +// } +// | { +// TAG: 14; // EvModule +// _0: { [key: string]: rescriptExport }; +// }; type rescriptDist = | { TAG: 0; _0: rescriptPointSetDist } @@ -116,86 +117,88 @@ type rescriptDeclarationArg = max: Date; }; -export type squiggleExpression = - | tagged<"symbol", string> - | tagged<"string", string> - | tagged<"call", string> - | tagged<"lambda", lambdaValue> - | tagged<"array", squiggleExpression[]> - | tagged<"arraystring", string[]> - | tagged<"boolean", boolean> - | tagged<"distribution", Distribution> - | tagged<"number", number> - | tagged<"date", Date> - | tagged<"timeDuration", number> - | tagged<"lambdaDeclaration", lambdaDeclaration> - | tagged<"record", { [key: string]: squiggleExpression }> - | tagged<"type", { [key: string]: squiggleExpression }> - | tagged<"typeIdentifier", string> - | tagged<"module", { [key: string]: squiggleExpression }> - | tagged<"void", string>; +// Umur: Squiggle expressions are opaque! +// export type squiggleExpression = +// | tagged<"symbol", string> +// | tagged<"string", string> +// | tagged<"call", string> +// | tagged<"lambda", lambdaValue> +// | tagged<"array", squiggleExpression[]> +// | tagged<"arraystring", string[]> +// | tagged<"boolean", boolean> +// | tagged<"distribution", Distribution> +// | tagged<"number", number> +// | tagged<"date", Date> +// | tagged<"timeDuration", number> +// | tagged<"lambdaDeclaration", lambdaDeclaration> +// | tagged<"record", { [key: string]: squiggleExpression }> +// | tagged<"type", { [key: string]: squiggleExpression }> +// | tagged<"typeIdentifier", string> +// | tagged<"module", { [key: string]: squiggleExpression }> +// | tagged<"void", string>; export { lambdaValue }; -export function convertRawToTypescript( - result: rescriptExport, - environment: environment -): squiggleExpression { - if (typeof result === "number") { - // EvVoid - return tag("void", ""); - } - switch (result.TAG) { - case 0: // EvArray - return tag( - "array", - result._0.map((x) => convertRawToTypescript(x, environment)) - ); - case 1: // EvArrayString - return tag("arraystring", result._0); - case 2: // EvBool - return tag("boolean", result._0); - case 3: // EvCall - return tag("call", result._0); - case 4: // EvDistribution - return tag( - "distribution", - new Distribution( - convertRawDistributionToGenericDist(result._0), - environment - ) - ); - case 5: // EvDistribution - return tag("lambda", result._0); - case 6: // EvNumber - return tag("number", result._0); - case 7: // EvRecord - return tag( - "record", - _.mapValues(result._0, (x) => convertRawToTypescript(x, environment)) - ); - case 8: // EvString - return tag("string", result._0); - case 9: // EvSymbol - return tag("symbol", result._0); - case 10: // EvDate - return tag("date", result._0); - case 11: // EvTimeDuration - return tag("number", result._0); - case 12: // EvDeclaration - return tag("lambdaDeclaration", { - fn: result._0.fn, - args: result._0.args.map(convertDeclaration), - }); - case 13: // EvSymbol - return tag("typeIdentifier", result._0); - case 14: // EvModule - return tag( - "module", - _.mapValues(result._0, (x) => convertRawToTypescript(x, environment)) - ); - } -} +// Umur: Opaque type no conversion! +// export function convertRawToTypescript( +// result: rescriptExport, +// environment: environment +// ): squiggleExpression { +// if (typeof result === "number") { +// // EvVoid +// return tag("void", ""); +// } +// switch (result.TAG) { +// case 0: // EvArray +// return tag( +// "array", +// result._0.map((x) => convertRawToTypescript(x, environment)) +// ); +// case 1: // EvArrayString +// return tag("arraystring", result._0); +// case 2: // EvBool +// return tag("boolean", result._0); +// case 3: // EvCall +// return tag("call", result._0); +// case 4: // EvDistribution +// return tag( +// "distribution", +// new Distribution( +// convertRawDistributionToGenericDist(result._0), +// environment +// ) +// ); +// case 5: // EvDistribution +// return tag("lambda", result._0); +// case 6: // EvNumber +// return tag("number", result._0); +// case 7: // EvRecord +// return tag( +// "record", +// _.mapValues(result._0, (x) => convertRawToTypescript(x, environment)) +// ); +// case 8: // EvString +// return tag("string", result._0); +// case 9: // EvSymbol +// return tag("symbol", result._0); +// case 10: // EvDate +// return tag("date", result._0); +// case 11: // EvTimeDuration +// return tag("number", result._0); +// case 12: // EvDeclaration +// return tag("lambdaDeclaration", { +// fn: result._0.fn, +// args: result._0.args.map(convertDeclaration), +// }); +// case 13: // EvSymbol +// return tag("typeIdentifier", result._0); +// case 14: // EvModule +// return tag( +// "module", +// _.mapValues(result._0, (x) => convertRawToTypescript(x, environment)) +// ); +// } +// } function convertDeclaration( declarationArg: rescriptDeclarationArg