diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res index 97068765..319535c1 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.res @@ -1,4 +1,3 @@ -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 7cdc3706..68da9534 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionOperation.resi @@ -1,4 +1,3 @@ -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/GenericDist.res b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res index 2db7a05d..c2bdd299 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.res @@ -1,5 +1,4 @@ //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 diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi index ba69c1f3..fd04212a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist.resi @@ -1,5 +1,3 @@ -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/ForTS/ForTS_ReducerProject.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res index daf945b9..27302313 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_ReducerProject.res @@ -1,6 +1,5 @@ @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 diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res deleted file mode 100644 index 99c4bceb..00000000 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_Result.res +++ /dev/null @@ -1,44 +0,0 @@ -@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) - -@genType -let getError = (r: result_<'a, 'e>): option<'e> => - switch r { - | Ok(_) => None - | Error(e) => Some(e) - } - -@genType -let getValue = (r: result<'a, 'e>): option<'a> => - switch r { - | Ok(v) => Some(v) - | Error(_) => None - } - -@module("./ForTS_Result_tag") @scope("resultTag") -external rtOk_: int = "RtOk" - -@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>): resultTag => - switch r { - | Ok(_) => rtOk_->castEnum - | Error(_) => rtError_->castEnum - } - -@genType -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 2091415b..73da47b3 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,9 @@ -export enum resultTag { - RtOk, - RtError, -} +export type result = + | { + tag: "Ok"; + value: a; + } + | { + tag: "Error"; + value: b; + }; diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res index 30ce6f8c..df5510d5 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue.res @@ -1,5 +1,4 @@ @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 @genType type squiggleValue_Array = ReducerInterface_InternalExpressionValue.squiggleArray //re-export recursive type @@ -97,7 +96,7 @@ let toString = (variant: squiggleValue) => // This is a useful method for unit tests. // Convert the result along with the error message to a string. @genType -let toStringResult = (variantResult: result_) => +let toStringResult = (variantResult: result) => ReducerInterface_InternalExpressionValue.toStringResult(variantResult) @genType diff --git a/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res b/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res index 88d22b65..b97c93e0 100644 --- a/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res +++ b/packages/squiggle-lang/src/rescript/ForTS/ForTS__Types.res @@ -1,5 +1,3 @@ -@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 diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index 16076f52..428fb0cd 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -15,12 +15,12 @@ The below few seem to work fine. In the future there's definitely more work to d @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 resultDist = result //alternative +@genType type resultFloat = result //alternative +@genType type resultString = result //alternative @genType -let makeSampleSetDist: array => result_< +let makeSampleSetDist: array => result< sampleSetDist, SampleSetDist.sampleSetError, > = SampleSetDist.make @@ -33,7 +33,7 @@ let toPointSet: ( ~sampleCount: int, ~xSelection: DistributionTypes.DistributionOperation.pointsetXSelection=?, unit, -) => result_ = GenericDist.toPointSet +) => result = GenericDist.toPointSet @genType type mixedShape = PointSetTypes.mixedShape