From ddfd4e002421712f524ccdab8c85367f3623a7d5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 29 Aug 2022 20:59:49 +0400 Subject: [PATCH] cleanup commented old code --- packages/squiggle-lang/src/js/index.ts | 136 --------- .../squiggle-lang/src/js/oldDistribution.ts | 252 ---------------- .../squiggle-lang/src/js/rescript_interop.ts | 279 ------------------ 3 files changed, 667 deletions(-) delete mode 100644 packages/squiggle-lang/src/js/oldDistribution.ts delete mode 100644 packages/squiggle-lang/src/js/rescript_interop.ts diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index 232ef45b..0a528e02 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -33,139 +33,3 @@ export const run = ( const bindings = project.getBindings("main"); return { result, bindings }; }; - -// import { -// jsValueToBinding, -// jsValueToExpressionValue, -// jsValue, -// rescriptExport, -// squiggleExpression, -// convertRawToTypescript, -// lambdaValue, -// } from "./rescript_interop"; - -// export function runForeign( -// fn: lambdaValue, -// args: jsValue[], -// environment?: environment -// ): result { -// let e = environment ? environment : defaultEnvironment; -// let res: result = foreignFunctionInterface( -// fn, -// args.map(jsValueToExpressionValue), -// e -// ); -// return resultMap(res, (x) => createTsExport(x, e)); -// } - -// function mergeImportsWithBindings( -// bindings: externalBindings, -// imports: jsImports -// ): externalBindings { -// let transformedImports = Object.fromEntries( -// Object.entries(imports).map(([key, value]) => [ -// "$" + key, -// jsValueToBinding(value), -// ]) -// ); -// return _.merge(bindings, transformedImports); -// } - -// type jsImports = { [key: string]: jsValue }; - -// export let defaultImports: jsImports = {}; -// export let defaultBindings: externalBindings = {}; - -// export function mergeBindings( -// allBindings: externalBindings[] -// ): externalBindings { -// return allBindings.reduce((acc, x) => ({ ...acc, ...x })); -// } - -// function createTsExport( -// x: expressionValue, -// environment: environment -// ): squiggleExpression { -// switch (x) { -// case "EvVoid": -// return tag("void", ""); -// default: { -// switch (x.tag) { -// case "EvArray": -// // genType doesn't convert anything more than 2 layers down into {tag: x, value: x} -// // format, leaving it as the raw values. This converts the raw values -// // directly into typescript values. -// // -// // The casting here is because genType is about the types of the returned -// // values, claiming they are fully recursive when that's not actually the -// // case -// return tag( -// "array", -// x.value.map( -// (arrayItem): squiggleExpression => -// convertRawToTypescript( -// arrayItem as unknown as rescriptExport, -// environment -// ) -// ) -// ); -// case "EvArrayString": -// return tag("arraystring", x.value); -// case "EvBool": -// return tag("boolean", x.value); -// case "EvCall": -// return tag("call", x.value); -// case "EvLambda": -// return tag("lambda", x.value); -// case "EvDistribution": -// return tag("distribution", new Distribution(x.value, environment)); -// case "EvNumber": -// return tag("number", x.value); -// case "EvRecord": -// // genType doesn't support records, so we have to do the raw conversion ourself -// let result: tagged<"record", { [key: string]: squiggleExpression }> = -// tag( -// "record", -// _.mapValues(x.value, (x: unknown) => -// convertRawToTypescript(x as rescriptExport, environment) -// ) -// ); -// return result; -// case "EvString": -// return tag("string", x.value); -// case "EvSymbol": -// return tag("symbol", x.value); -// case "EvDate": -// return tag("date", x.value); -// case "EvTimeDuration": -// return tag("timeDuration", x.value); -// case "EvDeclaration": -// return tag("lambdaDeclaration", x.value); -// case "EvTypeIdentifier": -// return tag("typeIdentifier", x.value); -// case "EvType": -// let typeResult: tagged< -// "type", -// { [key: string]: squiggleExpression } -// > = tag( -// "type", -// _.mapValues(x.value, (x: unknown) => -// convertRawToTypescript(x as rescriptExport, environment) -// ) -// ); -// return typeResult; -// case "EvModule": -// let moduleResult: tagged< -// "module", -// { [key: string]: squiggleExpression } -// > = tag( -// "module", -// _.mapValues(x.value, (x: unknown) => -// convertRawToTypescript(x as rescriptExport, environment) -// ) -// ); -// return moduleResult; -// } -// } -// } -// } diff --git a/packages/squiggle-lang/src/js/oldDistribution.ts b/packages/squiggle-lang/src/js/oldDistribution.ts deleted file mode 100644 index c68eb5a7..00000000 --- a/packages/squiggle-lang/src/js/oldDistribution.ts +++ /dev/null @@ -1,252 +0,0 @@ -// import * as _ from "lodash"; -// import { -// genericDist, -// continuousShape, -// discreteShape, -// environment, -// distributionError, -// toPointSet, -// distributionErrorToString, -// } from "../rescript/TypescriptInterface.gen"; -// import { result, resultMap, Ok } from "./types"; -// import { -// Constructors_mean, -// Constructors_stdev, -// Constructors_sample, -// Constructors_pdf, -// Constructors_cdf, -// Constructors_inv, -// Constructors_normalize, -// Constructors_isNormalized, -// Constructors_toPointSet, -// Constructors_toSampleSet, -// Constructors_truncate, -// Constructors_inspect, -// Constructors_toString, -// Constructors_toSparkline, -// Constructors_algebraicAdd, -// Constructors_algebraicMultiply, -// Constructors_algebraicDivide, -// Constructors_algebraicSubtract, -// Constructors_algebraicLogarithm, -// Constructors_algebraicPower, -// Constructors_pointwiseAdd, -// Constructors_pointwiseMultiply, -// Constructors_pointwiseDivide, -// Constructors_pointwiseSubtract, -// Constructors_pointwiseLogarithm, -// Constructors_pointwisePower, -// } from "../rescript/Distributions/DistributionOperation.gen"; - -// export type point = { x: number; y: number }; - -// function shapePoints(x: continuousShape | discreteShape): point[] { -// let xs = x.xyShape.xs; -// let ys = x.xyShape.ys; -// return _.zipWith(xs, ys, (x, y) => ({ x, y })); -// } -// export type shape = { -// continuous: point[]; -// discrete: point[]; -// }; - -// export class Distribution { -// t: genericDist; -// env: environment; - -// constructor(t: genericDist, env: environment) { -// this.t = t; -// this.env = env; -// return this; -// } - -// mapResultDist( -// r: result -// ): result { -// return resultMap(r, (v: genericDist) => new Distribution(v, this.env)); -// } - -// mean(): result { -// return Constructors_mean({ env: this.env }, this.t); -// } - -// stdev(): result { -// return Constructors_stdev({ env: this.env }, this.t); -// } - -// sample(): result { -// return Constructors_sample({ env: this.env }, this.t); -// } - -// pdf(n: number): result { -// return Constructors_pdf({ env: this.env }, this.t, n); -// } - -// cdf(n: number): result { -// return Constructors_cdf({ env: this.env }, this.t, n); -// } - -// inv(n: number): result { -// return Constructors_inv({ env: this.env }, this.t, n); -// } - -// isNormalized(): result { -// return Constructors_isNormalized({ env: this.env }, this.t); -// } - -// normalize(): result { -// return this.mapResultDist( -// Constructors_normalize({ env: this.env }, this.t) -// ); -// } - -// type() { -// return this.t.tag; -// } - -// pointSet(): result { -// let pointSet = toPointSet( -// this.t, -// { -// xyPointLength: this.env.xyPointLength, -// sampleCount: this.env.sampleCount, -// }, -// undefined -// ); -// if (pointSet.tag === "Ok") { -// let distribution = pointSet.value; -// if (distribution.tag === "Continuous") { -// return Ok({ -// continuous: shapePoints(distribution.value), -// discrete: [], -// }); -// } else if (distribution.tag === "Discrete") { -// return Ok({ -// discrete: shapePoints(distribution.value), -// continuous: [], -// }); -// } else { -// return Ok({ -// discrete: shapePoints(distribution.value.discrete), -// continuous: shapePoints(distribution.value.continuous), -// }); -// } -// } else { -// return pointSet; -// } -// } - -// toPointSet(): result { -// return this.mapResultDist( -// Constructors_toPointSet({ env: this.env }, this.t) -// ); -// } - -// toSampleSet(n: number): result { -// return this.mapResultDist( -// Constructors_toSampleSet({ env: this.env }, this.t, n) -// ); -// } - -// truncate( -// left: number, -// right: number -// ): result { -// return this.mapResultDist( -// Constructors_truncate({ env: this.env }, this.t, left, right) -// ); -// } - -// inspect(): result { -// return this.mapResultDist(Constructors_inspect({ env: this.env }, this.t)); -// } - -// toString(): string { -// let result = Constructors_toString({ env: this.env }, this.t); -// if (result.tag === "Ok") { -// return result.value; -// } else { -// return distributionErrorToString(result.value); -// } -// } - -// toSparkline(n: number): result { -// return Constructors_toSparkline({ env: this.env }, this.t, n); -// } - -// algebraicAdd(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_algebraicAdd({ env: this.env }, this.t, d2.t) -// ); -// } - -// algebraicMultiply(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_algebraicMultiply({ env: this.env }, this.t, d2.t) -// ); -// } - -// algebraicDivide(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_algebraicDivide({ env: this.env }, this.t, d2.t) -// ); -// } - -// algebraicSubtract(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_algebraicSubtract({ env: this.env }, this.t, d2.t) -// ); -// } - -// algebraicLogarithm( -// d2: Distribution -// ): result { -// return this.mapResultDist( -// Constructors_algebraicLogarithm({ env: this.env }, this.t, d2.t) -// ); -// } - -// algebraicPower(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_algebraicPower({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwiseAdd(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_pointwiseAdd({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwiseMultiply(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_pointwiseMultiply({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwiseDivide(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_pointwiseDivide({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwiseSubtract(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_pointwiseSubtract({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwiseLogarithm( -// d2: Distribution -// ): result { -// return this.mapResultDist( -// Constructors_pointwiseLogarithm({ env: this.env }, this.t, d2.t) -// ); -// } - -// pointwisePower(d2: Distribution): result { -// return this.mapResultDist( -// Constructors_pointwisePower({ env: this.env }, this.t, d2.t) -// ); -// } -// } diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts deleted file mode 100644 index 1031dd3e..00000000 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ /dev/null @@ -1,279 +0,0 @@ -/** - Umur: Delete this file! There is nothing left to see here. -**/ - -// import * as _ from "lodash"; -// import type { -// // expressionValue, -// mixedShape, -// sampleSetDist, -// genericDist, -// // environment, -// symbolicDist, -// discreteShape, -// continuousShape, -// // lambdaValue, -// // lambdaDeclaration, -// // declarationArg, -// } from "../rescript/TypescriptInterface.gen"; -// import { Distribution } from "./distribution"; -// import { tagged, tag } from "./types"; -// This file is here to compensate for genType not fully recursively converting types - -// Raw rescript types. -// 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 }; -// }; - -// Umur: opaque type -// type rescriptDist = -// | { TAG: 0; _0: rescriptPointSetDist } -// | { TAG: 1; _0: sampleSetDist } -// | { TAG: 2; _0: symbolicDist }; - -// Umur: opaque type, no conversion -// type rescriptPointSetDist = -// | { -// TAG: 0; // Mixed -// _0: mixedShape; -// } -// | { -// TAG: 1; // Discrete -// _0: discreteShape; -// } -// | { -// TAG: 2; // ContinuousShape -// _0: continuousShape; -// }; - -// type rescriptLambdaDeclaration = { -// readonly fn: lambdaValue; -// readonly args: rescriptDeclarationArg[]; -// }; - -// type rescriptDeclarationArg = -// | { -// TAG: 0; // Float -// min: number; -// max: number; -// } -// | { -// TAG: 1; // Date -// min: Date; -// max: Date; -// }; - -// 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 }; - -// 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 -// ): declarationArg { -// switch (declarationArg.TAG) { -// case 0: // Float -// return tag("Float", { min: declarationArg.min, max: declarationArg.max }); -// case 1: // Date -// return tag("Date", { min: declarationArg.min, max: declarationArg.max }); -// } -// } - -// Umur: opaque type no conversion! -// function convertRawDistributionToGenericDist( -// result: rescriptDist -// ): genericDist { -// switch (result.TAG) { -// case 0: // Point Set Dist -// switch (result._0.TAG) { -// case 0: // Mixed -// return tag("PointSet", tag("Mixed", result._0._0)); -// case 1: // Discrete -// return tag("PointSet", tag("Discrete", result._0._0)); -// case 2: // Continuous -// return tag("PointSet", tag("Continuous", result._0._0)); -// } -// case 1: // Sample Set Dist -// return tag("SampleSet", result._0); -// case 2: // Symbolic Dist -// return tag("Symbolic", result._0); -// } -// } - -// export type jsValue = -// | string -// | number -// | jsValue[] -// | { [key: string]: jsValue } -// | boolean; - -// export function jsValueToBinding(value: jsValue): rescriptExport { -// if (typeof value === "boolean") { -// return { TAG: 2, _0: value as boolean }; -// } else if (typeof value === "string") { -// return { TAG: 8, _0: value as string }; -// } else if (typeof value === "number") { -// return { TAG: 6, _0: value as number }; -// } else if (Array.isArray(value)) { -// return { TAG: 0, _0: value.map(jsValueToBinding) }; -// } else { -// // Record -// return { TAG: 7, _0: _.mapValues(value, jsValueToBinding) }; -// } -// } - -// export function jsValueToExpressionValue(value: jsValue): expressionValue { -// if (typeof value === "boolean") { -// return { tag: "EvBool", value: value as boolean }; -// } else if (typeof value === "string") { -// return { tag: "EvString", value: value as string }; -// } else if (typeof value === "number") { -// return { tag: "EvNumber", value: value as number }; -// } else if (Array.isArray(value)) { -// return { tag: "EvArray", value: value.map(jsValueToExpressionValue) }; -// } else { -// // Record -// return { -// tag: "EvRecord", -// value: _.mapValues(value, jsValueToExpressionValue), -// }; -// } -// }