From 25e78373704c2b9f2ff939b5b5e38aac3f2a6171 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 24 Oct 2022 12:00:57 -0400 Subject: [PATCH] Remove remaining |> usage except some tests --- .../AlgebraicShapeCombination.res | 48 +++++++++---------- .../PointSetDist/MixedShapeBuilder.res | 4 +- .../SampleSetDist/SampleSetDist_Bandwidth.res | 2 +- .../src/rescript/FR/FR_GenericDist.res | 4 +- .../src/rescript/Utility/E/E_JsArray.res | 6 --- .../src/rescript/Utility/E/E_O.res | 2 +- .../src/rescript/Utility/E/E_R.res | 1 - 7 files changed, 30 insertions(+), 37 deletions(-) delete mode 100644 packages/squiggle-lang/src/rescript/Utility/E/E_JsArray.res diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res index 101d4c9a6c..322a6ec0e7 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res @@ -16,28 +16,28 @@ let toDiscretePointMassesFromTriangulars = ( s: XYShape.T.t, ): pointMassesWithMoments => { // TODO: what if there is only one point in the distribution? - let n = s |> XYShape.T.length + let n = s->XYShape.T.length // first, double up the leftmost and rightmost points: let {xs, ys}: XYShape.T.t = s - Js.Array.unshift(xs[0], xs) |> ignore - Js.Array.unshift(ys[0], ys) |> ignore - Js.Array.push(xs[n - 1], xs) |> ignore - Js.Array.push(ys[n - 1], ys) |> ignore + Js.Array.unshift(xs[0], xs)->ignore + Js.Array.unshift(ys[0], ys)->ignore + Js.Array.push(xs[n - 1], xs)->ignore + Js.Array.push(ys[n - 1], ys)->ignore let n = E.A.length(xs) // squares and neighbourly products of the xs let xsSq: array = Belt.Array.makeUninitializedUnsafe(n) let xsProdN1: array = Belt.Array.makeUninitializedUnsafe(n - 1) let xsProdN2: array = Belt.Array.makeUninitializedUnsafe(n - 2) for i in 0 to n - 1 { - Belt.Array.set(xsSq, i, xs[i] *. xs[i]) |> ignore + Belt.Array.set(xsSq, i, xs[i] *. xs[i])->ignore () } for i in 0 to n - 2 { - Belt.Array.set(xsProdN1, i, xs[i] *. xs[i + 1]) |> ignore + Belt.Array.set(xsProdN1, i, xs[i] *. xs[i + 1])->ignore () } for i in 0 to n - 3 { - Belt.Array.set(xsProdN2, i, xs[i] *. xs[i + 2]) |> ignore + Belt.Array.set(xsProdN2, i, xs[i] *. xs[i + 2])->ignore () } // means and variances @@ -47,7 +47,7 @@ let toDiscretePointMassesFromTriangulars = ( if inverse { for i in 1 to n - 2 { - Belt.Array.set(masses, i - 1, (xs[i + 1] -. xs[i - 1]) *. ys[i] /. 2.) |> ignore + Belt.Array.set(masses, i - 1, (xs[i + 1] -. xs[i - 1]) *. ys[i] /. 2.)->ignore // this only works when the whole triange is either on the left or on the right of zero let a = xs[i - 1] @@ -63,9 +63,9 @@ let toDiscretePointMassesFromTriangulars = ( 2. *. (log(c /. a) /. (a -. c) +. b *. log(b /. c) /. (b -. c)) /. (a -. b) -. inverseMean ** 2. - Belt.Array.set(means, i - 1, inverseMean) |> ignore + Belt.Array.set(means, i - 1, inverseMean)->ignore - Belt.Array.set(variances, i - 1, inverseVar) |> ignore + Belt.Array.set(variances, i - 1, inverseVar)->ignore () } @@ -73,10 +73,10 @@ let toDiscretePointMassesFromTriangulars = ( } else { for i in 1 to n - 2 { // area of triangle = width * height / 2 - Belt.Array.set(masses, i - 1, (xs[i + 1] -. xs[i - 1]) *. ys[i] /. 2.) |> ignore + Belt.Array.set(masses, i - 1, (xs[i + 1] -. xs[i - 1]) *. ys[i] /. 2.)->ignore // means of triangle = (a + b + c) / 3 - Belt.Array.set(means, i - 1, (xs[i - 1] +. xs[i] +. xs[i + 1]) /. 3.) |> ignore + Belt.Array.set(means, i - 1, (xs[i - 1] +. xs[i] +. xs[i + 1]) /. 3.)->ignore // variance of triangle = (a^2 + b^2 + c^2 - ab - ac - bc) / 18 Belt.Array.set( @@ -88,7 +88,7 @@ let toDiscretePointMassesFromTriangulars = ( xsProdN1[i - 1] -. xsProdN1[i] -. xsProdN2[i - 1]) /. 18., - ) |> ignore + )->ignore () } {n: n - 2, masses, means, variances} @@ -127,7 +127,7 @@ let combineShapesContinuousContinuous = ( for i in 0 to t1m.n - 1 { for j in 0 to t2m.n - 1 { let k = i * t2m.n + j - Belt.Array.set(masses, k, t1m.masses[i] *. t2m.masses[j]) |> ignore + Belt.Array.set(masses, k, t1m.masses[i] *. t2m.masses[j])->ignore let mean = combineMeansFn(t1m.means[i], t2m.means[j]) let variance = combineVariancesFn( @@ -136,8 +136,8 @@ let combineShapesContinuousContinuous = ( t1m.means[i], t2m.means[j], ) - Belt.Array.set(means, k, mean) |> ignore - Belt.Array.set(variances, k, variance) |> ignore + Belt.Array.set(means, k, mean)->ignore + Belt.Array.set(variances, k, variance)->ignore // update bounds let minX = mean -. 2. *. sqrt(variance) *. 1.644854 let maxX = mean +. 2. *. sqrt(variance) *. 1.644854 @@ -168,7 +168,7 @@ let combineShapesContinuousContinuous = ( masses[j] *. exp(-.(dx ** 2.) /. (2. *. variances[j])) /. sqrt(2. *. 3.14159276 *. variances[j]) - Belt.Array.set(outputYs, i, outputYs[i] +. contribution) |> ignore + Belt.Array.set(outputYs, i, outputYs[i] +. contribution)->ignore } } } @@ -195,8 +195,8 @@ let combineShapesContinuousDiscrete = ( discreteShape: PointSetTypes.xyShape, ~discretePosition: argumentPosition, ): PointSetTypes.xyShape => { - let t1n = continuousShape |> XYShape.T.length - let t2n = discreteShape |> XYShape.T.length + let t1n = continuousShape->XYShape.T.length + let t2n = discreteShape->XYShape.T.length // each x pair is added/subtracted let opFunc = Operation.Convolution.toFn(op) @@ -222,9 +222,9 @@ let combineShapesContinuousDiscrete = ( fn(continuousShape.xs[i], discreteShape.xs[j]), continuousShape.ys[i] *. discreteShape.ys[j], ), - ) |> ignore + )->ignore } - Belt.Array.set(outXYShapes, j, dxyShape) |> ignore + Belt.Array.set(outXYShapes, j, dxyShape)->ignore () } | #Multiply => @@ -243,10 +243,10 @@ let combineShapesContinuousDiscrete = ( fn(continuousShape.xs[i], discreteShape.xs[j]), continuousShape.ys[i] *. discreteShape.ys[j] /. Js.Math.abs_float(discreteShape.xs[j]), ), - ) |> ignore + )->ignore () } - Belt.Array.set(outXYShapes, j, dxyShape) |> ignore + Belt.Array.set(outXYShapes, j, dxyShape)->ignore } } diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/MixedShapeBuilder.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/MixedShapeBuilder.res index 824e1f808a..da99ff49b4 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/MixedShapeBuilder.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/MixedShapeBuilder.res @@ -16,8 +16,8 @@ let buildSimple = ( continuous->E.O.defaultFn(() => Continuous.make(~integralSumCache=Some(0.0), {xs: [], ys: []})) let discrete = discrete->E.O.defaultFn(() => Discrete.make(~integralSumCache=Some(0.0), {xs: [], ys: []})) - let cLength = continuous |> Continuous.getShape |> XYShape.T.xs |> E.A.length - let dLength = discrete |> Discrete.getShape |> XYShape.T.xs |> E.A.length + let cLength = continuous->Continuous.getShape->XYShape.T.xs->E.A.length + let dLength = discrete->Discrete.getShape->XYShape.T.xs->E.A.length switch (cLength, dLength) { | (0 | 1, 0) => None | (0 | 1, _) => Some(Discrete(discrete)) diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res index 29d48ad352..0ecd8c6e8a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res @@ -2,7 +2,7 @@ let {iqr_percentile, nrd0_lo_denominator, one, nrd0_coef, nrd_coef, nrd_fractionalPower} = module( MagicNumbers.SampleSetBandwidth ) -let len = x => E.A.length(x) |> float_of_int +let len = x => E.A.length(x)->float_of_int let iqr = x => Jstat.percentile(x, iqr_percentile, true) -. Jstat.percentile(x, 1.0 -. iqr_percentile, true) diff --git a/packages/squiggle-lang/src/rescript/FR/FR_GenericDist.res b/packages/squiggle-lang/src/rescript/FR/FR_GenericDist.res index d9e33a8b0a..9d8c5ec478 100644 --- a/packages/squiggle-lang/src/rescript/FR/FR_GenericDist.res +++ b/packages/squiggle-lang/src/rescript/FR/FR_GenericDist.res @@ -75,7 +75,7 @@ module Old = { } let parseNumberArray = (ags: array): Belt.Result.t, string> => - E.A.fmap(ags, parseNumber) |> E.A.R.firstErrorOrOpen + E.A.fmap(ags, parseNumber)->E.A.R.firstErrorOrOpen let parseDist = (args: Reducer_T.value): Belt.Result.t => switch args { @@ -87,7 +87,7 @@ module Old = { let parseDistributionArray = (ags: array): Belt.Result.t< array, string, - > => E.A.fmap(ags, parseDist) |> E.A.R.firstErrorOrOpen + > => E.A.fmap(ags, parseDist)->E.A.R.firstErrorOrOpen let mixtureWithGivenWeights = ( distributions: array, diff --git a/packages/squiggle-lang/src/rescript/Utility/E/E_JsArray.res b/packages/squiggle-lang/src/rescript/Utility/E/E_JsArray.res deleted file mode 100644 index c5a65d84c7..0000000000 --- a/packages/squiggle-lang/src/rescript/Utility/E/E_JsArray.res +++ /dev/null @@ -1,6 +0,0 @@ -module O = E_O -let concatSomes = (optionals: Js.Array.t>): Js.Array.t<'a> => - optionals - |> Js.Array.filter(O.isSome) - |> Js.Array.map(E_O.toExn(_, "Warning: This should not have happened")) -let filter = Js.Array.filter diff --git a/packages/squiggle-lang/src/rescript/Utility/E/E_O.res b/packages/squiggle-lang/src/rescript/Utility/E/E_O.res index 30a5dbb01b..6437befa9c 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E/E_O.res +++ b/packages/squiggle-lang/src/rescript/Utility/E/E_O.res @@ -60,7 +60,7 @@ let apply = (o, a) => | Some(f) => bind(a, b => some(f(b))) | _ => None } -let flatApply = (fn, b) => apply(fn, Some(b)) |> flatten +let flatApply = (fn, b) => apply(fn, Some(b))->flatten let toBool = opt => switch opt { diff --git a/packages/squiggle-lang/src/rescript/Utility/E/E_R.res b/packages/squiggle-lang/src/rescript/Utility/E/E_R.res index 9c9f93b647..7d36244a1a 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E/E_R.res +++ b/packages/squiggle-lang/src/rescript/Utility/E/E_R.res @@ -8,7 +8,6 @@ let result = (okF, errF, r) => | Ok(a) => okF(a) | Error(err) => errF(err) } -let id = e => e |> result(e => e, e => e) let isOk = Belt.Result.isOk let getError = (r: result<'a, 'b>) => switch r {