diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index 15346d67..c5f66eed 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -10,7 +10,6 @@ Instead of a global function namespace we should use modules under ForTS directl */ - import * as _ from "lodash"; import type { environment, @@ -57,7 +56,6 @@ export let defaultSamplingInputs: environment = { xyPointLength: 10000, }; - /* Umur: All the functions below are invalid. ForTS_Reducer project is the new way to do this. */ // export function run( diff --git a/packages/squiggle-lang/src/js/rescript_interop.ts b/packages/squiggle-lang/src/js/rescript_interop.ts index b6bcbba0..1031dd3e 100644 --- a/packages/squiggle-lang/src/js/rescript_interop.ts +++ b/packages/squiggle-lang/src/js/rescript_interop.ts @@ -1,19 +1,23 @@ -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"; +/** + 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. @@ -81,24 +85,26 @@ import { tagged, tag } from "./types"; // _0: { [key: string]: rescriptExport }; // }; -type rescriptDist = - | { TAG: 0; _0: rescriptPointSetDist } - | { TAG: 1; _0: sampleSetDist } - | { TAG: 2; _0: symbolicDist }; +// Umur: opaque type +// type rescriptDist = +// | { TAG: 0; _0: rescriptPointSetDist } +// | { TAG: 1; _0: sampleSetDist } +// | { TAG: 2; _0: symbolicDist }; -type rescriptPointSetDist = - | { - TAG: 0; // Mixed - _0: mixedShape; - } - | { - TAG: 1; // Discrete - _0: discreteShape; - } - | { - TAG: 2; // ContinuousShape - _0: continuousShape; - }; +// 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; @@ -211,32 +217,33 @@ type rescriptPointSetDist = // } // } -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); - } -} +// 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 type jsValue = +// | string +// | number +// | jsValue[] +// | { [key: string]: jsValue } +// | boolean; // export function jsValueToBinding(value: jsValue): rescriptExport { // if (typeof value === "boolean") { diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res index 319535c1..97068765 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res @@ -1,3 +1,4 @@ +type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type type functionCallInfo = DistributionTypes.DistributionOperation.genericFunctionCallInfo type genericDist = DistributionTypes.genericDist type error = DistributionTypes.error diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi index 68da9534..7cdc3706 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi @@ -1,3 +1,4 @@ +type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type @genType let defaultEnv: GenericDist.env diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res index ab272c7f..93f934e1 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res @@ -1,4 +1,5 @@ -@genType +//FIXME accessor methods or not opaque? +@genType.opaque type genericDist = | PointSet(PointSetTypes.pointSetDist) | SampleSet(SampleSetDist.t) @@ -6,6 +7,7 @@ type genericDist = type asAlgebraicCombinationStrategy = AsDefault | AsSymbolic | AsMonteCarlo | AsConvolution +@genType.opaque type error = | NotYetImplemented | Unreachable diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res index f536d54d..2db7a05d 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res @@ -1,4 +1,6 @@ //TODO: multimodal, add interface, test somehow, track performance, refactor sampleSet, refactor ASTEvaluator.res. +type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type + type t = DistributionTypes.genericDist type error = DistributionTypes.error type toPointSetFn = t => result diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi index fd04212a..ba69c1f3 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi @@ -1,3 +1,5 @@ +type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type + type t = DistributionTypes.genericDist type error = DistributionTypes.error type toPointSetFn = t => result diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetTypes.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetTypes.res index fcc796ec..76720290 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetTypes.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/PointSetTypes.res @@ -47,7 +47,7 @@ type pointSetDistMonad<'a, 'b, 'c> = | Discrete('b) | Continuous('c) -@genType +@genType.opaque type pointSetDist = pointSetDistMonad module ShapeMonad = { diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution.res new file mode 100644 index 00000000..ca4c02ad --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution.res @@ -0,0 +1,57 @@ +// Genetic Distribution happens to be abstract distribution +@genType type distribution = DistributionTypes.genericDist +@genType type pointSetDistribution = ForTS_Distribution_PointSetDistribution.pointSetDistribution +@genType type sampleSetDistribution = ForTS_Distribution_SampleSetDistribution.sampleSetDistribution +@genType type symbolicDistribution = ForTS_Distribution_SymbolicDistribution.symbolicDistribution + +type environment = ForTS_Distribution_Environment.environment //use + +@genType +let defaultEnvironment: environment = DistributionOperation.defaultEnv + +@module("ForTS_Distribution_tag") @scope("distributionTag") +external dtPointSet_: int = "DtPointSet" + +@module("ForTS_Distribution_tag") @scope("distributionTag") +external dtSampleSet_: int = "DtSampleSet" + +@module("ForTS_Distribution_tag") @scope("distributionTag") +external dtSymbolic_: int = "DtSymbolic" + +@genType.import("./ForTS_Distribution_tag") +type distributionTag + +external castEnum: int => distributionTag = "%identity" + +// type genericDist = +// | PointSet(PointSetTypes.pointSetDist) +// | SampleSet(SampleSetDist.t) +// | Symbolic(SymbolicDistTypes.symbolicDist) +@genType +let getTag = (variant: distribution): distributionTag => + switch variant { + | PointSet(_) => dtPointSet_->castEnum + | SampleSet(_) => dtSampleSet_->castEnum + | Symbolic(_) => dtSymbolic_->castEnum + } + +@genType +let getPointSet = (variant: distribution): option => + switch variant { + | PointSet(dist) => dist->Some + | _ => None + } + +@genType +let getSampleSet = (variant: distribution): option => + switch variant { + | SampleSet(dist) => dist->Some + | _ => None + } + +@genType +let getSymbolic = (variant: distribution): option => + switch variant { + | Symbolic(dist) => dist->Some + | _ => None + } diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.res new file mode 100644 index 00000000..d6f89fb9 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.res @@ -0,0 +1 @@ +@genType type environment = GenericDist.env //re-export diff --git a/packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions_Error.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Error.res similarity index 60% rename from packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions_Error.res rename to packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Error.res index fff8f232..d228e7b2 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions_Error.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Error.res @@ -1,4 +1,4 @@ -open ForTS__Types +@genType type distributionError = DistributionTypes.error @genType let toString = (e: distributionError) => DistributionTypes.Error.toString(e) diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res new file mode 100644 index 00000000..59750a15 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution.res @@ -0,0 +1,44 @@ +@genType type pointSetDistribution = PointSetTypes.pointSetDist + +@module("ForTS_Distribution_PointSetDistribution_tag") @scope("pointSetDistributionTag") +external pstMixed_: int = "PstMixed" + +@module("ForTS_Distribution_PointSetDistribution_tag") @scope("pointSetDistributionTag") +external pstDiscrete_: int = "PstDiscrete" + +@module("ForTS_Distribution_PointSetDistribution_tag") @scope("pointSetDistributionTag") +external pstContinuous_: int = "PstContinuous" + +@genType.import("./ForTS_Distribution_PointSetDistribution_tag") +type pointSetDistributionTag + +external castEnum: int => pointSetDistributionTag = "%identity" + +@genType +let getTag = (variant: pointSetDistribution): pointSetDistributionTag => + switch variant { + | Mixed(_) => pstMixed_->castEnum + | Discrete(_) => pstDiscrete_->castEnum + | Continuous(_) => pstContinuous_->castEnum + } + +@genType +let getMixed = (variant: pointSetDistribution): 'd => + switch variant { + | Mixed(mixed) => mixed->Some + | _ => None + } + +@genType +let getDiscrete = (variant: pointSetDistribution): 'd => + switch variant { + | Discrete(discrete) => discrete->Some + | _ => None + } + +@genType +let getContinues = (variant: pointSetDistribution): 'd => + switch variant { + | Continuous(continuous) => continuous->Some + | _ => None + } diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.js b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.js new file mode 100644 index 00000000..106c13d2 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.js @@ -0,0 +1,15 @@ +"use strict"; +exports.__esModule = true; +exports.pointSetDistributionTag = void 0; +var pointSetDistributionTag; +(function (pointSetDistributionTag) { + pointSetDistributionTag[(pointSetDistributionTag["PstMixed"] = 0)] = + "PstMixed"; + pointSetDistributionTag[(pointSetDistributionTag["PstDiscrete"] = 1)] = + "PstDiscrete"; + pointSetDistributionTag[(pointSetDistributionTag["PstContinuous"] = 2)] = + "PstContinuous"; +})( + (pointSetDistributionTag = + exports.pointSetDistributionTag || (exports.pointSetDistributionTag = {})) +); diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.ts b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.ts new file mode 100644 index 00000000..e1e16d89 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_PointSetDistribution_tag.ts @@ -0,0 +1,5 @@ +export enum pointSetDistributionTag { + PstMixed, + PstDiscrete, + PstContinuous, +} diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SampleSetDistribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SampleSetDistribution.res new file mode 100644 index 00000000..29f0c2aa --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SampleSetDistribution.res @@ -0,0 +1 @@ +@genType type sampleSetDistribution = SampleSetDist.t diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SymbolicDistribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SymbolicDistribution.res new file mode 100644 index 00000000..32e8614b --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_SymbolicDistribution.res @@ -0,0 +1 @@ +@genType type symbolicDistribution = SymbolicDistTypes.symbolicDist diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_tag.ts b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_tag.ts new file mode 100644 index 00000000..72466c91 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Distribution/ForTS_Distribution_tag.ts @@ -0,0 +1,5 @@ +export enum distributionTag { + DtPointSet, + DtSampleSet, + DtSymbolic, +} diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res index a195a046..d35dd156 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res @@ -1,6 +1,13 @@ -open ForTS__Types -// If a module is built for TypeScript then it can only refer to ForTS__Types for other types and modules -// The exception is its implementation and private modules +@genType type reducerProject = ReducerProject_T.t //re-export + +type result<'a, 'e> = ForTS_Result.result<'a, 'e> // Use opaque result type +type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use + +type squiggleValue = ForTS_SquiggleValue.squiggleValue //use +type squiggleValue_Module = ForTS_SquiggleValue_Module.squiggleValue_Module //use + +type environment = ForTS_Distribution_Environment.environment //use + module T = ReducerProject_T module Private = ReducerProject.Private @@ -9,6 +16,8 @@ module Private = ReducerProject.Private */ /* +A project links and runs sources that continue or include each other. + Creates a new project to hold the sources, executables, bindings, and other data. The new project runs the sources according to their topological sorting because of the includes and continues. @@ -92,7 +101,7 @@ let cleanAllResults = (project: reducerProject): unit => To set the includes one first has to call "parseIncludes". The parsed includes or the parser error is returned. */ @genType -let getIncludes = (project: reducerProject, sourceId: string): result_< +let getIncludes = (project: reducerProject, sourceId: string): result< array, reducerErrorValue, > => project->T.Private.castToInternalProject->Private.getIncludes(sourceId) @@ -145,7 +154,7 @@ let getRunOrderFor = (project: reducerProject, sourceId: string) => Parse includes so that you can load them before running. Load includes by calling getIncludes which returns the includes that have been parsed. It is your responsibility to load the includes before running. -*/ module Topology = ReducerProject_Topology +*/ @genType let parseIncludes = (project: reducerProject, sourceId: string): unit => @@ -186,7 +195,7 @@ Get the result after running this source file or the project */ @genType let getResult = (project: reducerProject, sourceId: string): option< - result_, + result, > => project->T.Private.castToInternalProject->Private.getResult(sourceId) /* @@ -194,7 +203,11 @@ This is a convenience function to get the result of a single source without crea However, without a project, you cannot handle include directives. The source has to be include free */ -@genType let evaluate = (sourceCode: string): ('r, 'b) => Private.evaluate(sourceCode) +@genType +let evaluate = (sourceCode: string): ( + result, + squiggleValue_Module, +) => Private.evaluate(sourceCode) @genType let setEnvironment = (project: reducerProject, environment: environment): unit => @@ -211,7 +224,7 @@ If the conversion to the new project is too difficult, I can add it later. // lambdaValue: squiggleValue_Lambda, // argArray: array, // environment: environment, -// ): result_ => { +// ): result => { // let accessors = ReducerProject_ProjectAccessors_T.identityAccessorsWithEnvironment(environment) // Reducer_Expression_Lambda.foreignFunctionInterface( // lambdaValue, diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res index 32541a06..61dc3bac 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Reducer_ErrorValue.res @@ -1,4 +1,5 @@ -open ForTS__Types +@genType type reducerErrorValue = Reducer_ErrorValue.errorValue //alias +@genType type syntaxErrorLocation = Reducer_ErrorValue.syntaxErrorLocation //alias @genType let toString = (e: reducerErrorValue): string => Reducer_ErrorValue.errorToString(e) diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res index 39aad100..6c770dc6 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res @@ -1,4 +1,5 @@ -open ForTS__Types +@genType.opaque type result_<'a, 'e> = result<'a, 'e> +@genType type result<'a, 'e> = result_<'a, 'e> // alias and re-export @genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r) @genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r) @@ -11,27 +12,32 @@ let getError = (r: result_<'a, 'e>): option<'e> => } @genType -let getValue = (r: result_<'a, 'e>): option<'a> => +let getValue = (r: result<'a, 'e>): option<'a> => switch r { | Ok(v) => Some(v) | Error(_) => None } -@module("ForTS_Result_tag") @scope("ResultTag") +@module("ForTS_Result_tag") @scope("resultTag") external rtOk_: int = "RtOk" -@module("ForTS_Result_tag") @scope("ResultTag") +@module("ForTS_Result_tag") @scope("resultTag") external rtError_: int = "RtError" +@genType.import("./ForTS_Result_tag") +type resultTag + +external castEnum: int => resultTag = "%identity" + @genType -let getTag = (r: result_<'a, 'e>): int => +let getTag = (r: result<'a, 'e>): resultTag => switch r { - | Ok(_) => rtOk_ - | Error(_) => rtError_ + | Ok(_) => rtOk_->castEnum + | Error(_) => rtError_->castEnum } @genType -let fmap = (r: result_<'a, 'e>, f: 'a => 'b): result_<'b, 'e> => +let fmap = (r: result<'a, 'e>, f: 'a => 'b): result<'b, 'e> => switch r { | Ok(v) => Ok(f(v)) | Error(e) => Error(e) diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result_tag.ts b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result_tag.ts index 571de93a..da7cd79d 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result_tag.ts +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result_tag.ts @@ -1,4 +1,4 @@ -enum ResultTag { - Ok, - Error, -} \ No newline at end of file +export enum resultTag { + Ok, + Error, +} diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res similarity index 54% rename from packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue.res rename to packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res index 893c50b3..3d7586ff 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res @@ -1,78 +1,93 @@ -open ForTS__Types +@genType type squiggleValue = ReducerInterface_InternalExpressionValue.t //re-export +type result_<'a, 'e> = ForTS_Result.result_<'a, 'e> //use +type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use -// Return values as they are if they are JavaScript types. +@genType type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray //re-export recursive type +@genType type squiggleValue_Module = ReducerInterface_InternalExpressionValue.nameSpace //re-export recursive type +@genType type squiggleValue_Record = ReducerInterface_InternalExpressionValue.map //re-export recursive type +@genType type squiggleValue_Type = ReducerInterface_InternalExpressionValue.map //re-export recursive type +type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //use +type squiggleValue_Distribution = ForTS_SquiggleValue_Distribution.squiggleValue_Distribution //use +type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //use -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +// Return values are kept as they are if they are JavaScript types. + +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtArray_: int = "SvtArray" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtArrayString_: int = "SvtArrayString" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtBool_: int = "SvtBool" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtCall_: int = "SvtCall" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtDate_: int = "SvtDate" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtDeclaration_: int = "SvtDeclaration" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtDistribution_: int = "SvtDistribution" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtLambda_: int = "SvtLambda" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtModule_: int = "SvtModule" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtNumber_: int = "SvtNumber" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtRecord_: int = "SvtRecord" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtString_: int = "SvtString" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtSymbol_: int = "SvtSymbol" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtTimeDuration_: int = "SvtTimeDuration" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtType_: int = "SvtType" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtTypeIdentifier_: int = "SvtUndefined" -@module("ForTS_SquiggleValue_tag") @scope("SquiggleValueTag") +@module("ForTS_SquiggleValue_tag") @scope("squiggleValueTag") external svtVoid_: int = "SvtVoid" +@genType.import("./ForTS_SquiggleValue_tag") +type squiggleValueTag + +external castEnum: int => squiggleValueTag = "%identity" + @genType -let getTag = (variant: squiggleValue) => +let getTag = (variant: squiggleValue): squiggleValueTag => switch variant { - | IEvArray(_) => svtArray_ - | IEvArrayString(_) => svtArrayString_ - | IEvBool(_) => svtBool_ - | IEvCall(_) => svtCall_ //Impossible - | IEvDate(_) => svtDate_ - | IEvDeclaration(_) => svtDeclaration_ - | IEvDistribution(_) => svtDistribution_ - | IEvLambda(_) => svtLambda_ - | IEvBindings(_) => svtModule_ //Impossible - | IEvNumber(_) => svtNumber_ - | IEvRecord(_) => svtRecord_ - | IEvString(_) => svtString_ - | IEvSymbol(_) => svtSymbol_ - | IEvTimeDuration(_) => svtTimeDuration_ - | IEvType(_) => svtType_ - | IEvTypeIdentifier(_) => svtTypeIdentifier_ - | IEvVoid => svtVoid_ + | IEvArray(_) => svtArray_->castEnum + | IEvArrayString(_) => svtArrayString_->castEnum + | IEvBool(_) => svtBool_->castEnum + | IEvCall(_) => svtCall_->castEnum //Impossible + | IEvDate(_) => svtDate_->castEnum + | IEvDeclaration(_) => svtDeclaration_->castEnum + | IEvDistribution(_) => svtDistribution_->castEnum + | IEvLambda(_) => svtLambda_->castEnum + | IEvBindings(_) => svtModule_->castEnum //Impossible + | IEvNumber(_) => svtNumber_->castEnum + | IEvRecord(_) => svtRecord_->castEnum + | IEvString(_) => svtString_->castEnum + | IEvSymbol(_) => svtSymbol_->castEnum + | IEvTimeDuration(_) => svtTimeDuration_->castEnum + | IEvType(_) => svtType_->castEnum + | IEvTypeIdentifier(_) => svtTypeIdentifier_->castEnum + | IEvVoid => svtVoid_->castEnum } @genType diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.res index e90b493b..61b84d74 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Array.res @@ -1,6 +1,5 @@ -open ForTS__Types -// Note: Internal representation will not be an array in the future. -// Thus we still to have a conversion +type squiggleValue = ForTS_SquiggleValue.squiggleValue +@genType type squiggleValue_Array = ForTS_SquiggleValue.squiggleValue_Array //re-export recursive type @genType let getValues = (v: squiggleValue_Array): array => diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Declaration.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Declaration.res new file mode 100644 index 00000000..b53fb4bf --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Declaration.res @@ -0,0 +1 @@ +@genType type squiggleValue_Declaration = ReducerInterface_InternalExpressionValue.lambdaDeclaration //re-export diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Distribution.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Distribution.res new file mode 100644 index 00000000..ef20d02f --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Distribution.res @@ -0,0 +1 @@ +@genType type squiggleValue_Distribution = ForTS_Distribution.distribution diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Lambda.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Lambda.res new file mode 100644 index 00000000..c41a5727 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Lambda.res @@ -0,0 +1 @@ +@genType type squiggleValue_Lambda = ReducerInterface_InternalExpressionValue.lambdaValue //re-export 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 2c06b9d7..8bb113a2 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 @@ -1,4 +1,5 @@ -open ForTS__Types +type squiggleValue = ForTS_SquiggleValue.squiggleValue //use +@genType type squiggleValue_Module = ForTS_SquiggleValue.squiggleValue_Module //re-export recursive type @genType let getKeyValuePairs = (v: squiggleValue_Module): array<(string, squiggleValue)> => diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.res index 5fa0da2d..bc226f95 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.res @@ -1,4 +1,5 @@ -open ForTS__Types +type squiggleValue = ForTS_SquiggleValue.squiggleValue //use +@genType type squiggleValue_Record = ForTS_SquiggleValue.squiggleValue_Record //re-export recursive type @genType let getKeyValuePairs = (value: squiggleValue_Record): array<(string, squiggleValue)> => diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Type.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Type.res index b0a91495..d9a18bfc 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Type.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Type.res @@ -1,4 +1,5 @@ -open ForTS__Types +type squiggleValue = ForTS_SquiggleValue.squiggleValue //use +@genType type squiggleValue_Type = ForTS_SquiggleValue.squiggleValue_Type //re-export recursive type @genType let getKeyValuePairs = (value: squiggleValue_Type): array<(string, squiggleValue)> => diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag.ts b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag.ts new file mode 100644 index 00000000..6393ca60 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_tag.ts @@ -0,0 +1,19 @@ +export enum squiggleValueTag { + SvtArray, + SvtArrayString, + SvtBool, + SvtCall, + SvtDate, + SvtDeclaration, + SvtDistribution, + SvtLambda, + SvtModule, + SvtNumber, + SvtRecord, + SvtString, + SvtSymbol, + SvtTimeDuration, + SvtType, + SvtTypeIdentifier, + SvtVoid, +} diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue_tag.ts b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue_tag.ts deleted file mode 100644 index 9e4b34fd..00000000 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue_tag.ts +++ /dev/null @@ -1,19 +0,0 @@ -enum SquiggleValueTag { - SvtArray, - SvtArrayString, - SvtBool, - SvtCall, - SvtDate, - SvtDeclaration, - SvtDistribution, - SvtLambda, - SvtModule, - SvtNumber, - SvtRecord, - SvtString, - SvtSymbol, - SvtTimeDuration, - SvtType, - SvtTypeIdentifier, - SvtVoid, -} \ No newline at end of file diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res index f3041750..4826324f 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res @@ -1,31 +1,24 @@ -@genType.opaque type result_<'a, 'e> = result<'a, 'e> -@genType.opaque type reducerErrorValue = Reducer_ErrorValue.errorValue -@genType type syntaxErrorLocation = Reducer_ErrorValue.syntaxErrorLocation +@genType type result_<'a, 'e> = ForTS_Result.result_<'a, 'e> //re-export +@genType type result<'a, 'e> = ForTS_Result.result<'a, 'e> //re-export +@genType type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //re-export +@genType type syntaxErrorLocation = ForTS_Reducer_ErrorValue.syntaxErrorLocation //re-export -/* -The reason this is not ExpressionValue is that ExpressionValue is becoming a parametric type -to allow expressions for different domains. -So we rename it right away not cause a compatibility problem -*/ -@genType.opaque type squiggleValue = ReducerInterface_InternalExpressionValue.t -@genType.opaque type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray -@genType.opaque -type squiggleValue_Declaration = ReducerInterface_InternalExpressionValue.lambdaDeclaration -@genType.opaque type squiggleValue_Module = ReducerInterface_InternalExpressionValue.nameSpace -@genType.opaque type squiggleValue_Lambda = ReducerInterface_InternalExpressionValue.lambdaValue -@genType.opaque type squiggleValue_Record = ReducerInterface_InternalExpressionValue.map -@genType.opaque type squiggleValue_Type = ReducerInterface_InternalExpressionValue.map - -@genType.opaque type reducerProject = ReducerProject_T.t +@genType type reducerProject = ForTS_ReducerProject.reducerProject //re-export +@genType type squiggleValue = ForTS_SquiggleValue.squiggleValue //re-export +@genType type squiggleValue_Array = ForTS_SquiggleValue_Array.squiggleValue_Array //re-export +@genType type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //re-export +@genType type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //re-export +@genType type squiggleValue_Module = ForTS_SquiggleValue_Module.squiggleValue_Module //re-export +@genType type squiggleValue_Record = ForTS_SquiggleValue_Record.squiggleValue_Record //re-export +@genType type squiggleValue_Type = ForTS_SquiggleValue_Type.squiggleValue_Type //re-export /* Distribution related */ -@genType type environment = GenericDist.env -@genType.opaque -type distributionError = DistributionTypes.error +@genType type squiggleValue_Distribution = ForTS_Distribution.distribution //re-export +@genType type distribution = squiggleValue_Distribution //candid +@genType type distributionError = ForTS_Distribution_Error.distributionError //re-export +@genType type environment = ForTS_Distribution_Environment.environment //re-export -// From now on one should introduce any new types as opaque types. -// Exception: The intended type is really a JavaScript type or record. Not by coincidence -// Already existing open types we cannot dive in now -@genType type squiggleValue_Distribution = DistributionTypes.genericDist +@genType type pointSetDistribution = ForTS_Distribution_PointSetDistribution.pointSetDistribution //re-export +@genType type sampleSetDistribution = ForTS_Distribution_SampleSetDistribution.sampleSetDistribution //re-export +@genType type symbolicDistribution = ForTS_Distribution_SymbolicDistribution.symbolicDistribution //re-export -//TODO: index.ts should use types from here or vice versa diff --git a/packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions.res b/packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions.res deleted file mode 100644 index 9e01f4e1..00000000 --- a/packages/squiggle-lang/src/rescript/ForTS/For_TS_Distributions/For_TS_Distributions.res +++ /dev/null @@ -1,4 +0,0 @@ -open ForTS__Types - -@genType -let defaultEnvironment: environment = DistributionOperation.defaultEnv diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res index 3ff122ca..a3d1acff 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_ErrorValue.res @@ -2,6 +2,7 @@ @gentype.import("peggy") @genType.as("LocationRange") type syntaxErrorLocation +@genType.opaque type errorValue = | REArityError(option, int, int) | REArrayIndexNotFound(string, int) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res index 9d47c741..6a26ecd2 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_InternalExpressionValue.res @@ -5,6 +5,7 @@ type environment = GenericDist.env let defaultEnvironment: environment = DistributionOperation.defaultEnv +@genType.opaque type rec t = | IEvArray(array) // FIXME: Convert to MapInt | IEvArrayString(array) @@ -23,17 +24,17 @@ type rec t = | IEvType(map) | IEvTypeIdentifier(string) | IEvVoid -and squiggleArray = array -and map = Belt.Map.String.t -and nameSpace = NameSpace(Belt.Map.String.t) +@genType.opaque and squiggleArray = array +@genType.opaque and map = Belt.Map.String.t +@genType.opaque and nameSpace = NameSpace(Belt.Map.String.t) +@genType.opaque and lambdaValue = { parameters: array, context: nameSpace, body: internalCode, } -and lambdaDeclaration = Declaration.declaration +@genType.opaque and lambdaDeclaration = Declaration.declaration -type squiggleMap = map type internalExpressionValue = t type functionCall = (string, array) diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js index adc6e598..cb8c66eb 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_IncludeParser.js @@ -5,7 +5,9 @@ "use strict"; function peg$subclass(child, parent) { - function C() { this.constructor = child; } + function C() { + this.constructor = child; + } C.prototype = parent.prototype; child.prototype = new C(); } @@ -27,13 +29,15 @@ peg$subclass(peg$SyntaxError, Error); function peg$padEnd(str, targetLength, padString) { padString = padString || " "; - if (str.length > targetLength) { return str; } + if (str.length > targetLength) { + return str; + } targetLength -= str.length; padString += padString.repeat(targetLength); return str + padString.slice(0, targetLength); } -peg$SyntaxError.prototype.format = function(sources) { +peg$SyntaxError.prototype.format = function (sources) { var str = "Error: " + this.message; if (this.location) { var src = null; @@ -48,15 +52,24 @@ peg$SyntaxError.prototype.format = function(sources) { var loc = this.location.source + ":" + s.line + ":" + s.column; if (src) { var e = this.location.end; - var filler = peg$padEnd("", s.line.toString().length, ' '); + var filler = peg$padEnd("", s.line.toString().length, " "); var line = src[s.line - 1]; var last = s.line === e.line ? e.column : line.length + 1; - var hatLen = (last - s.column) || 1; - str += "\n --> " + loc + "\n" - + filler + " |\n" - + s.line + " | " + line + "\n" - + filler + " | " + peg$padEnd("", s.column - 1, ' ') - + peg$padEnd("", hatLen, "^"); + var hatLen = last - s.column || 1; + str += + "\n --> " + + loc + + "\n" + + filler + + " |\n" + + s.line + + " | " + + line + + "\n" + + filler + + " | " + + peg$padEnd("", s.column - 1, " ") + + peg$padEnd("", hatLen, "^"); } else { str += "\n at " + loc; } @@ -64,33 +77,35 @@ peg$SyntaxError.prototype.format = function(sources) { return str; }; -peg$SyntaxError.buildMessage = function(expected, found) { +peg$SyntaxError.buildMessage = function (expected, found) { var DESCRIBE_EXPECTATION_FNS = { - literal: function(expectation) { - return "\"" + literalEscape(expectation.text) + "\""; + literal: function (expectation) { + return '"' + literalEscape(expectation.text) + '"'; }, - class: function(expectation) { - var escapedParts = expectation.parts.map(function(part) { + class: function (expectation) { + var escapedParts = expectation.parts.map(function (part) { return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); }); - return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"; + return ( + "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + ); }, - any: function() { + any: function () { return "any character"; }, - end: function() { + end: function () { return "end of input"; }, - other: function(expectation) { + other: function (expectation) { return expectation.description; - } + }, }; function hex(ch) { @@ -100,13 +115,17 @@ peg$SyntaxError.buildMessage = function(expected, found) { function literalEscape(s) { return s .replace(/\\/g, "\\\\") - .replace(/"/g, "\\\"") + .replace(/"/g, '\\"') .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") - .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); + .replace(/[\x00-\x0F]/g, function (ch) { + return "\\x0" + hex(ch); + }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { + return "\\x" + hex(ch); + }); } function classEscape(s) { @@ -114,13 +133,17 @@ peg$SyntaxError.buildMessage = function(expected, found) { .replace(/\\/g, "\\\\") .replace(/\]/g, "\\]") .replace(/\^/g, "\\^") - .replace(/-/g, "\\-") + .replace(/-/g, "\\-") .replace(/\0/g, "\\0") .replace(/\t/g, "\\t") .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") - .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); }) - .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); }); + .replace(/[\x00-\x0F]/g, function (ch) { + return "\\x0" + hex(ch); + }) + .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { + return "\\x" + hex(ch); + }); } function describeExpectation(expectation) { @@ -151,17 +174,25 @@ peg$SyntaxError.buildMessage = function(expected, found) { return descriptions[0] + " or " + descriptions[1]; default: - return descriptions.slice(0, -1).join(", ") - + ", or " - + descriptions[descriptions.length - 1]; + return ( + descriptions.slice(0, -1).join(", ") + + ", or " + + descriptions[descriptions.length - 1] + ); } } function describeFound(found) { - return found ? "\"" + literalEscape(found) + "\"" : "end of input"; + return found ? '"' + literalEscape(found) + '"' : "end of input"; } - return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; + return ( + "Expected " + + describeExpected(expected) + + " but " + + describeFound(found) + + " found." + ); }; function peg$parse(input, options) { @@ -175,7 +206,7 @@ function peg$parse(input, options) { var peg$c0 = "#include"; var peg$c1 = "'"; - var peg$c2 = "\""; + var peg$c2 = '"'; var peg$c3 = "//"; var peg$c4 = "/*"; var peg$c5 = "*/"; @@ -191,8 +222,8 @@ function peg$parse(input, options) { var peg$e1 = peg$otherExpectation("string"); var peg$e2 = peg$literalExpectation("'", false); var peg$e3 = peg$classExpectation(["'"], true, false); - var peg$e4 = peg$literalExpectation("\"", false); - var peg$e5 = peg$classExpectation(["\""], true, false); + var peg$e4 = peg$literalExpectation('"', false); + var peg$e5 = peg$classExpectation(['"'], true, false); var peg$e6 = peg$literalExpectation("//", false); var peg$e7 = peg$literalExpectation("/*", false); var peg$e8 = peg$classExpectation(["*"], true, false); @@ -203,12 +234,24 @@ function peg$parse(input, options) { var peg$e13 = peg$classExpectation(["\n", "\r"], false, false); var peg$e14 = peg$classExpectation(["\r", "\n"], true, false); - var peg$f0 = function(head, tail) {return [head, ...tail].filter( e => e != '');}; - var peg$f1 = function() {return [];}; - var peg$f2 = function(characters) {return characters.join('');}; - var peg$f3 = function(characters) {return characters.join('');}; - var peg$f4 = function() { return '';}; - var peg$f5 = function() { return '';}; + var peg$f0 = function (head, tail) { + return [head, ...tail].filter((e) => e != ""); + }; + var peg$f1 = function () { + return []; + }; + var peg$f2 = function (characters) { + return characters.join(""); + }; + var peg$f3 = function (characters) { + return characters.join(""); + }; + var peg$f4 = function () { + return ""; + }; + var peg$f5 = function () { + return ""; + }; var peg$currPos = 0; var peg$savedPos = 0; var peg$posDetailsCache = [{ line: 1, column: 1 }]; @@ -222,7 +265,9 @@ function peg$parse(input, options) { if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { - throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); + throw new Error( + "Can't start parsing from rule \"" + options.startRule + '".' + ); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; @@ -240,7 +285,7 @@ function peg$parse(input, options) { return { source: peg$source, start: peg$savedPos, - end: peg$currPos + end: peg$currPos, }; } @@ -249,9 +294,10 @@ function peg$parse(input, options) { } function expected(description, location) { - location = location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); + location = + location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildStructuredError( [peg$otherExpectation(description)], @@ -261,9 +307,10 @@ function peg$parse(input, options) { } function error(message, location) { - location = location !== undefined - ? location - : peg$computeLocation(peg$savedPos, peg$currPos); + location = + location !== undefined + ? location + : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildSimpleError(message, location); } @@ -273,7 +320,12 @@ function peg$parse(input, options) { } function peg$classExpectation(parts, inverted, ignoreCase) { - return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; + return { + type: "class", + parts: parts, + inverted: inverted, + ignoreCase: ignoreCase, + }; } function peg$anyExpectation() { @@ -303,7 +355,7 @@ function peg$parse(input, options) { details = peg$posDetailsCache[p]; details = { line: details.line, - column: details.column + column: details.column, }; while (p < pos) { @@ -332,18 +384,20 @@ function peg$parse(input, options) { start: { offset: startPos, line: startPosDetails.line, - column: startPosDetails.column + column: startPosDetails.column, }, end: { offset: endPos, line: endPosDetails.line, - column: endPosDetails.column - } + column: endPosDetails.column, + }, }; } function peg$fail(expected) { - if (peg$currPos < peg$maxFailPos) { return; } + if (peg$currPos < peg$maxFailPos) { + return; + } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; @@ -501,7 +555,9 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } + if (peg$silentFails === 0) { + peg$fail(peg$e0); + } } if (s1 !== peg$FAILED) { s2 = []; @@ -559,7 +615,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { + peg$fail(peg$e2); + } } if (s2 !== peg$FAILED) { s3 = []; @@ -568,7 +626,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { + peg$fail(peg$e3); + } } while (s4 !== peg$FAILED) { s3.push(s4); @@ -577,7 +637,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { + peg$fail(peg$e3); + } } } if (input.charCodeAt(peg$currPos) === 39) { @@ -585,7 +647,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { + peg$fail(peg$e2); + } } if (s4 !== peg$FAILED) { s1 = s3; @@ -610,7 +674,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { + peg$fail(peg$e4); + } } if (s2 !== peg$FAILED) { s3 = []; @@ -619,7 +685,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { + peg$fail(peg$e5); + } } while (s4 !== peg$FAILED) { s3.push(s4); @@ -628,7 +696,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { + peg$fail(peg$e5); + } } } if (input.charCodeAt(peg$currPos) === 34) { @@ -636,7 +706,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { + peg$fail(peg$e4); + } } if (s4 !== peg$FAILED) { s1 = s3; @@ -657,7 +729,9 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } + if (peg$silentFails === 0) { + peg$fail(peg$e1); + } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -719,7 +793,9 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { + peg$fail(peg$e6); + } } if (s1 !== peg$FAILED) { s2 = []; @@ -758,7 +834,9 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { + peg$fail(peg$e7); + } } if (s1 !== peg$FAILED) { s2 = []; @@ -767,7 +845,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { + peg$fail(peg$e8); + } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -776,7 +856,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { + peg$fail(peg$e8); + } } } if (input.substr(peg$currPos, 2) === peg$c5) { @@ -784,7 +866,9 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } + if (peg$silentFails === 0) { + peg$fail(peg$e9); + } } if (s3 !== peg$FAILED) { peg$savedPos = s0; @@ -821,12 +905,16 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } + if (peg$silentFails === 0) { + peg$fail(peg$e11); + } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } + if (peg$silentFails === 0) { + peg$fail(peg$e10); + } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -852,12 +940,16 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { + peg$fail(peg$e13); + } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { + peg$fail(peg$e12); + } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -882,7 +974,9 @@ function peg$parse(input, options) { peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { + peg$fail(peg$e14); + } } peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; @@ -911,5 +1005,5 @@ function peg$parse(input, options) { module.exports = { SyntaxError: peg$SyntaxError, - parse: peg$parse + parse: peg$parse, }; diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res index c7bf968a..a9411c43 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res @@ -2,7 +2,10 @@ module ProjectItem = ReducerProject_ProjectItem module ExpressionT = Reducer_Expression_T module ProjectAccessorsT = ReducerProject_ProjectAccessors_T +@genType.opaque type project = {"tag": string} +//re-export +@genType type t = project module Private = { diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index 60ed0ad6..16076f52 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -8,28 +8,17 @@ would be preferable. The below few seem to work fine. In the future there's definitely more work to do here. */ -@genType -type samplingParams = environment +// For backwards compatibility: +//Alternatives if one wants to keep the old habits +@genType type samplingParams = environment +@genType type squiggleValue_Dist = squiggleValue_Distribution //alternative +@genType type genericDist = squiggleValue_Distribution //alternative +@genType type sampleSetDist = sampleSetDistribution //alternative +@genType type symbolicDist = symbolicDistribution //alternative +@genType type resultDist = result_ //alternative +@genType type resultFloat = result_ //alternative +@genType type resultString = result_ //alternative -@genType -type genericDist = squiggleValue_Distribution - -@genType -type sampleSetDist = SampleSetDist.t - -@genType -type symbolicDist = SymbolicDistTypes.symbolicDist - -@genType -type resultDist = result_ - -@genType -type resultFloat = result_ - -@genType -type resultString = result_ - -//TODO: ForTS Interface module candid @genType let makeSampleSetDist: array => result_< sampleSetDist, @@ -55,15 +44,15 @@ type discreteShape = PointSetTypes.discreteShape @genType type continuousShape = PointSetTypes.continuousShape -// ForTS_Distributions_Error.toString +@genType +let distributionErrorToString = ForTS_Distribution_Error.toString + +@genType +let defaultSamplingEnv = ForTS_Distribution.defaultEnvironment + +// Umur: opaqe types // @genType -// let distributionErrorToString = DistributionTypes.Error.toString +// type declarationArg = Declaration.arg -@genType -let defaultSamplingEnv = DistributionOperation.defaultEnv - -@genType -type declarationArg = Declaration.arg - -@genType -type declaration<'a> = Declaration.declaration<'a> +// @genType +// type declaration<'a> = Declaration.declaration<'a>