diff --git a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.res b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.res index e956a303..56a086ca 100644 --- a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.res @@ -29,7 +29,7 @@ let normalize = (t: t) => | #SampleSet(_) => t } -let operationToFloat = (toPointSet: toPointSetFn, fnName, t) => { +let operationToFloat = (t, toPointSet: toPointSetFn, fnName) => { let symbolicSolution = switch t { | #Symbolic(r) => switch SymbolicDist.T.operate(fnName, r) { @@ -83,10 +83,10 @@ module Truncate = { } let run = ( + t: t, toPointSet: toPointSetFn, leftCutoff: option, rightCutoff: option, - t: t, ): result => { let doesNotNeedCutoff = E.O.isNone(leftCutoff) && E.O.isNone(rightCutoff) if doesNotNeedCutoff { @@ -95,7 +95,7 @@ module Truncate = { switch trySymbolicSimplification(leftCutoff, rightCutoff, t) { | Some(r) => Ok(r) | None => - toPointSet(t) |> E.R.fmap(t => + toPointSet(t)->E.R.fmap2(t => #PointSet(PointSetDist.T.truncate(leftCutoff, rightCutoff, t)) ) } @@ -134,7 +134,7 @@ module AlgebraicCombination = { t1: t, t2: t, ) => - E.R.merge(toPointSet(t1), toPointSet(t2)) |> E.R.fmap(((a, b)) => + E.R.merge(toPointSet(t1), toPointSet(t2))->E.R.fmap2(((a, b)) => PointSetDist.combineAlgebraically(operation, a, b) ) @@ -145,8 +145,8 @@ module AlgebraicCombination = { t2: t, ) => { let operation = Operation.Algebraic.toFn(operation) - E.R.merge(toSampleSet(t1), toSampleSet(t2)) |> E.R.fmap(((a, b)) => { - Belt.Array.zip(a, b) |> E.A.fmap(((a, b)) => operation(a, b)) + E.R.merge(toSampleSet(t1), toSampleSet(t2)) -> E.R.fmap2(((a, b)) => { + Belt.Array.zip(a, b) -> E.A.fmap2(((a, b)) => operation(a, b)) }) } @@ -155,7 +155,7 @@ module AlgebraicCombination = { switch x { | #Symbolic(#Float(_)) => 1 | #Symbolic(_) => 1000 - | #PointSet(Discrete(m)) => m.xyShape |> XYShape.T.length + | #PointSet(Discrete(m)) => m.xyShape -> XYShape.T.length | #PointSet(Mixed(_)) => 1000 | #PointSet(Continuous(_)) => 1000 | _ => 1000 @@ -167,10 +167,10 @@ module AlgebraicCombination = { : #CalculateWithConvolution let run = ( + t1: t, toPointSet: toPointSetFn, toSampleSet: toSampleSetFn, algebraicOp, - t1: t, t2: t, ): result => { switch tryAnalyticalSimplification(algebraicOp, t1, t2) { @@ -190,7 +190,7 @@ module AlgebraicCombination = { let algebraicCombination = AlgebraicCombination.run //TODO: Add faster pointwiseCombine fn -let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t): result< +let pointwiseCombination = (t1: t, toPointSet: toPointSetFn, operation, t2: t): result< t, error, > => { @@ -202,10 +202,10 @@ let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t): } let pointwiseCombinationFloat = ( + t: t, toPointSet: toPointSetFn, operation: GenericDist_Types.Operation.arithmeticOperation, f: float, - t: t, ): result => { switch operation { | #Add | #Subtract => Error(GenericDist_Types.DistributionVerticalShiftIsInvalid) @@ -227,9 +227,9 @@ let pointwiseCombinationFloat = ( //Note: The result should always cumulatively sum to 1. let mixture = ( + values: array<(t, float)>, scaleMultiply: scaleMultiplyFn, pointwiseAdd: pointwiseAddFn, - values: array<(t, float)>, ) => { if E.A.length(values) == 0 { Error(GenericDist_Types.Other("mixture must have at least 1 element")) diff --git a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.resi b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.resi index 18dcc0eb..b7d6bb26 100644 --- a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.resi +++ b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist.resi @@ -13,32 +13,32 @@ let toString: t => string let normalize: t => t -let operationToFloat: (toPointSetFn, Operation.distToFloatOperation, t) => result +let operationToFloat: (t, toPointSetFn, Operation.distToFloatOperation) => result let toPointSet: (t, int) => result -let truncate: (toPointSetFn, option, option, t) => result +let truncate: (t, toPointSetFn, option, option) => result let algebraicCombination: ( + t, toPointSetFn, toSampleSetFn, GenericDist_Types.Operation.arithmeticOperation, t, - t, ) => result let pointwiseCombination: ( + t, toPointSetFn, GenericDist_Types.Operation.arithmeticOperation, t, - t, ) => result let pointwiseCombinationFloat: ( + t, toPointSetFn, GenericDist_Types.Operation.arithmeticOperation, float, - t, ) => result -let mixture: (scaleMultiplyFn, pointwiseAddFn, array<(t, float)>) => result +let mixture: (array<(t, float)>, scaleMultiplyFn, pointwiseAddFn) => result diff --git a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res index 8dbdfe5a..c3aa71f8 100644 --- a/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res +++ b/packages/squiggle-lang/src/rescript/GenericDist/GenericDist_GenericOperation.res @@ -93,7 +93,7 @@ let rec run = (extra, fnName: operation): outputType => { let fromDistFn = (subFn: GenericDist_Types.Operation.fromDist, dist: genericDist) => switch subFn { | #toFloat(fnName) => - GenericDist.operationToFloat(toPointSet, fnName, dist)->E.R.fmap2(r => #Float(r))->fromResult + GenericDist.operationToFloat(dist, toPointSet, fnName)->E.R.fmap2(r => #Float(r))->fromResult | #toString => dist->GenericDist.toString->(r => #String(r)) | #toDist(#consoleLog) => { Js.log2("Console log requested: ", dist) @@ -101,7 +101,7 @@ let rec run = (extra, fnName: operation): outputType => { } | #toDist(#normalize) => dist->GenericDist.normalize->(r => #Dist(r)) | #toDist(#truncate(left, right)) => - dist |> GenericDist.truncate(toPointSet, left, right) |> E.R.fmap(r => #Dist(r)) |> fromResult + dist->GenericDist.truncate(toPointSet, left, right)->E.R.fmap2(r => #Dist(r))->fromResult | #toDist(#toPointSet) => dist->GenericDist.toPointSet(xyPointLength)->E.R.fmap2(r => #Dist(#PointSet(r)))->fromResult | #toDist(#toSampleSet(n)) => @@ -109,26 +109,26 @@ let rec run = (extra, fnName: operation): outputType => { | #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented) | #toDistCombination(#Algebraic, operation, #Dist(dist2)) => dist - |> GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2) - |> E.R.fmap(r => #Dist(r)) - |> fromResult + ->GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2) + ->E.R.fmap2(r => #Dist(r)) + ->fromResult | #toDistCombination(#Pointwise, operation, #Dist(dist2)) => dist - |> GenericDist.pointwiseCombination(toPointSet, operation, dist2) - |> E.R.fmap(r => #Dist(r)) - |> fromResult + ->GenericDist.pointwiseCombination(toPointSet, operation, dist2) + ->E.R.fmap2(r => #Dist(r)) + ->fromResult | #toDistCombination(#Pointwise, operation, #Float(f)) => dist - |> GenericDist.pointwiseCombinationFloat(toPointSet, operation, f) - |> E.R.fmap(r => #Dist(r)) - |> fromResult + ->GenericDist.pointwiseCombinationFloat(toPointSet, operation, f) + ->E.R.fmap2(r => #Dist(r)) + ->fromResult } switch fnName { | #fromDist(subFn, dist) => fromDistFn(subFn, dist) | #fromFloat(subFn, float) => reCall(~fnName=#fromDist(subFn, GenericDist.fromFloat(float)), ()) | #mixture(dists) => - GenericDist.mixture(scaleMultiply, pointwiseAdd, dists)->E.R.fmap2(r => #Dist(r))->fromResult + dists->GenericDist.mixture(scaleMultiply, pointwiseAdd)->E.R.fmap2(r => #Dist(r))->fromResult } }