diff --git a/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res b/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res index 59f9b126..52ab6c19 100644 --- a/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res +++ b/packages/squiggle-lang/__tests__/GenericDist/GenericOperation__Test.res @@ -22,14 +22,14 @@ let toExt: option<'a> => 'a = E.O.toExt( describe("normalize", () => { test("has no impact on normal dist", () => { let result = run(#fromDist(#toDist(#normalize), normalDist)) - expect(result)->toEqual(#Dist(normalDist)) + expect(result)->toEqual(Dist(normalDist)) }) }) describe("mean", () => { test("for a normal distribution", () => { let result = GenericDist_GenericOperation.run(params, #fromDist(#toFloat(#Mean), normalDist)) - expect(result)->toEqual(#Float(5.0)) + expect(result)->toEqual(Float(5.0)) }) }) @@ -59,7 +59,7 @@ describe("toPointSet", () => { run(#fromDist(#toDist(#toPointSet), #SampleSet([0.0, 1.0, 2.0, 3.0])))->outputMap( #fromDist(#toFloat(#Mean)), ) - expect(result)->toEqual(#GenDistError(Other("Converting sampleSet to pointSet failed"))) + expect(result)->toEqual(GenDistError(Other("Converting sampleSet to pointSet failed"))) }) Skip.test("on sample set", () => { diff --git a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res index a90bb824..e744543e 100644 --- a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res +++ b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res @@ -9,35 +9,34 @@ type params = { xyPointLength: int, } -type outputType = [ - | #Dist(genericDist) - | #Float(float) - | #String(string) - | #GenDistError(error) -] +type outputType = + | Dist(GenericDist_Types.genericDist) + | Float(float) + | String(string) + | GenDistError(GenericDist_Types.error) module Output = { let toDist = (o: outputType) => switch o { - | #Dist(d) => Some(d) + | Dist(d) => Some(d) | _ => None } let toFloat = (o: outputType) => switch o { - | #Float(d) => Some(d) + | Float(d) => Some(d) | _ => None } let toString = (o: outputType) => switch o { - | #String(d) => Some(d) + | String(d) => Some(d) | _ => None } let toError = (o: outputType) => switch o { - | #GenDistError(d) => Some(d) + | GenDistError(d) => Some(d) | _ => None } } @@ -45,19 +44,19 @@ module Output = { let fromResult = (r: result): outputType => switch r { | Ok(o) => o - | Error(e) => #GenDistError(e) + | Error(e) => GenDistError(e) } //This is used to catch errors in other switch statements. let _errorMap = (o: outputType): error => switch o { - | #GenDistError(r) => r + | GenDistError(r) => r | _ => Unreachable } let outputToDistResult = (o: outputType): result => switch o { - | #Dist(r) => Ok(r) + | Dist(r) => Ok(r) | r => Error(_errorMap(r)) } @@ -70,14 +69,14 @@ let rec run = (extra, fnName: operation): outputType => { let toPointSetFn = r => { switch reCall(~fnName=#fromDist(#toDist(#toPointSet), r), ()) { - | #Dist(#PointSet(p)) => Ok(p) + | Dist(#PointSet(p)) => Ok(p) | r => Error(_errorMap(r)) } } let toSampleSetFn = r => { switch reCall(~fnName=#fromDist(#toDist(#toSampleSet(sampleCount)), r), ()) { - | #Dist(#SampleSet(p)) => Ok(p) + | Dist(#SampleSet(p)) => Ok(p) | r => Error(_errorMap(r)) } } @@ -98,37 +97,37 @@ let rec run = (extra, fnName: operation): outputType => { switch subFnName { | #toFloat(fnName) => GenericDist.operationToFloat(dist, ~toPointSetFn, ~operation=fnName) - ->E.R2.fmap(r => #Float(r)) + ->E.R2.fmap(r => Float(r)) ->fromResult - | #toString => dist->GenericDist.toString->(r => #String(r)) + | #toString => dist->GenericDist.toString->String | #toDist(#inspect) => { Js.log2("Console log requested: ", dist) - #Dist(dist) + Dist(dist) } - | #toDist(#normalize) => dist->GenericDist.normalize->(r => #Dist(r)) + | #toDist(#normalize) => dist->GenericDist.normalize->Dist | #toDist(#truncate(leftCutoff, rightCutoff)) => GenericDist.truncate(~toPointSetFn, ~leftCutoff, ~rightCutoff, dist, ()) - ->E.R2.fmap(r => #Dist(r)) + ->E.R2.fmap(r => Dist(r)) ->fromResult | #toDist(#toPointSet) => - dist->GenericDist.toPointSet(xyPointLength)->E.R2.fmap(r => #Dist(#PointSet(r)))->fromResult + dist->GenericDist.toPointSet(xyPointLength)->E.R2.fmap(r => Dist(#PointSet(r)))->fromResult | #toDist(#toSampleSet(n)) => - dist->GenericDist.sampleN(n)->E.R2.fmap(r => #Dist(#SampleSet(r)))->fromResult - | #toDistCombination(#Algebraic, _, #Float(_)) => #GenDistError(NotYetImplemented) + dist->GenericDist.sampleN(n)->E.R2.fmap(r => Dist(#SampleSet(r)))->fromResult + | #toDistCombination(#Algebraic, _, #Float(_)) => GenDistError(NotYetImplemented) | #toDistCombination(#Algebraic, operation, #Dist(t2)) => dist ->GenericDist.algebraicCombination(~toPointSetFn, ~toSampleSetFn, ~operation, ~t2) - ->E.R2.fmap(r => #Dist(r)) + ->E.R2.fmap(r => Dist(r)) ->fromResult | #toDistCombination(#Pointwise, operation, #Dist(t2)) => dist ->GenericDist.pointwiseCombination(~toPointSetFn, ~operation, ~t2) - ->E.R2.fmap(r => #Dist(r)) + ->E.R2.fmap(r => Dist(r)) ->fromResult | #toDistCombination(#Pointwise, operation, #Float(float)) => dist ->GenericDist.pointwiseCombinationFloat(~toPointSetFn, ~operation, ~float) - ->E.R2.fmap(r => #Dist(r)) + ->E.R2.fmap(r => Dist(r)) ->fromResult } @@ -139,7 +138,7 @@ let rec run = (extra, fnName: operation): outputType => { | #mixture(dists) => dists ->GenericDist.mixture(~scaleMultiplyFn=scaleMultiply, ~pointwiseAddFn=pointwiseAdd) - ->E.R2.fmap(r => #Dist(r)) + ->E.R2.fmap(r => Dist(r)) ->fromResult } } @@ -153,9 +152,9 @@ let outputMap = ( fn: GenericDist_Types.Operation.singleParamaterFunction, ): outputType => { let newFnCall: result = switch (fn, input) { - | (#fromDist(fromDist), #Dist(o)) => Ok(#fromDist(fromDist, o)) - | (#fromFloat(fromDist), #Float(o)) => Ok(#fromFloat(fromDist, o)) - | (_, #GenDistError(r)) => Error(r) + | (#fromDist(fromDist), Dist(o)) => Ok(#fromDist(fromDist, o)) + | (#fromFloat(fromDist), Float(o)) => Ok(#fromFloat(fromDist, o)) + | (_, GenDistError(r)) => Error(r) | (#fromDist(_), _) => Error(Other("Expected dist, got something else")) | (#fromFloat(_), _) => Error(Other("Expected float, got something else")) } diff --git a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.resi b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.resi index 37d6593a..22864ed3 100644 --- a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.resi +++ b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.resi @@ -3,12 +3,11 @@ type params = { xyPointLength: int, } -type outputType = [ - | #Dist(GenericDist_Types.genericDist) - | #GenDistError(GenericDist_Types.error) - | #Float(float) - | #String(string) -] +type outputType = + | Dist(GenericDist_Types.genericDist) + | Float(float) + | String(string) + | GenDistError(GenericDist_Types.error) let run: (params, GenericDist_Types.Operation.genericFunctionCallInfo) => outputType let runFromDist: ( @@ -17,7 +16,11 @@ let runFromDist: ( GenericDist_Types.genericDist, ) => outputType let runFromFloat: (params, GenericDist_Types.Operation.fromDist, float) => outputType -let outputMap: (params, outputType, GenericDist_Types.Operation.singleParamaterFunction) => outputType +let outputMap: ( + params, + outputType, + GenericDist_Types.Operation.singleParamaterFunction, +) => outputType module Output: { let toDist: outputType => option