From cfb969f2b383a7c555882c1e57eb1e789a047bfe Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Thu, 21 Apr 2022 18:42:15 -0400 Subject: [PATCH] Remove rescript warning 102 --- packages/squiggle-lang/bsconfig.json | 2 +- .../Distributions/GenericDist/GenericDist.res | 10 ++++++++-- .../squiggle-lang/src/rescript/Utility/E.res | 16 ++++++++++------ .../src/rescript/Utility/Sparklines.res | 2 +- .../src/rescript/Utility/XYShape.res | 8 ++++---- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/squiggle-lang/bsconfig.json b/packages/squiggle-lang/bsconfig.json index e529439c..b3e6c9ea 100644 --- a/packages/squiggle-lang/bsconfig.json +++ b/packages/squiggle-lang/bsconfig.json @@ -37,7 +37,7 @@ }, "refmt": 3, "warnings": { - "number": "+A-42-48-9-30-4-102" + "number": "+A-42-48-9-30-4" }, "ppx-flags": [ ["../../node_modules/bisect_ppx/ppx", "--exclude-files", ".*_test\\.res$$"] diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res index 9e9dd3c7..e39d01b7 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res @@ -101,10 +101,16 @@ let toSparkline = (t: t, ~sampleCount: int, ~bucketCount: int=20, ()): result => + let trySymbolicSimplification = ( + leftCutoff: option, + rightCutoff: option, + t: t, + ): option => switch (leftCutoff, rightCutoff, t) { | (None, None, _) => None - | (lc, rc, Symbolic(#Uniform(u))) if lc < rc => + | (Some(lc), Some(rc), Symbolic(#Uniform(u))) if lc < rc => + Some(Symbolic(#Uniform(SymbolicDist.Uniform.truncate(Some(lc), Some(rc), u)))) + | (lc, rc, Symbolic(#Uniform(u))) => Some(Symbolic(#Uniform(SymbolicDist.Uniform.truncate(lc, rc, u)))) | _ => None } diff --git a/packages/squiggle-lang/src/rescript/Utility/E.res b/packages/squiggle-lang/src/rescript/Utility/E.res index 24e7947c..8c6c4511 100644 --- a/packages/squiggle-lang/src/rescript/Utility/E.res +++ b/packages/squiggle-lang/src/rescript/Utility/E.res @@ -28,7 +28,7 @@ module Int = { } /* Utils */ module U = { - let isEqual = (a, b) => a == b + let isEqual = \"==" let toA = a => [a] let id = e => e } @@ -340,8 +340,6 @@ module A = { let reduce = Belt.Array.reduce let reducei = Belt.Array.reduceWithIndex let isEmpty = r => length(r) < 1 - let min = a => get(a, 0) |> O.fmap(first => Belt.Array.reduce(a, first, (i, j) => i < j ? i : j)) - let max = a => get(a, 0) |> O.fmap(first => Belt.Array.reduce(a, first, (i, j) => i > j ? i : j)) let stableSortBy = Belt.SortArray.stableSortBy let toRanges = (a: array<'a>) => switch a |> Belt.Array.length { @@ -448,8 +446,11 @@ module A = { | (Some(min), Some(max)) => Some(max -. min) | _ => None } + + let floatCompare: (float, float) => int = compare + let binarySearchFirstElementGreaterIndex = (ar: array<'a>, el: 'a) => { - let el = Belt.SortArray.binarySearchBy(ar, el, compare) + let el = Belt.SortArray.binarySearchBy(ar, el, floatCompare) let el = el < 0 ? el * -1 - 1 : el switch el { | e if e >= length(ar) => #overMax @@ -460,13 +461,13 @@ module A = { let concat = (t1: array<'a>, t2: array<'a>) => { let ts = Belt.Array.concat(t1, t2) - ts |> Array.fast_sort(compare) + ts |> Array.fast_sort(floatCompare) ts } let concatMany = (t1: array>) => { let ts = Belt.Array.concatMany(t1) - ts |> Array.fast_sort(compare) + ts |> Array.fast_sort(floatCompare) ts } @@ -525,6 +526,9 @@ module A = { let diff = (max -. min) /. Belt.Float.fromInt(n - 1) Belt.Array.makeBy(n, i => min +. Belt.Float.fromInt(i) *. diff) } + + let min = Js.Math.minMany_float + let max = Js.Math.maxMany_float } } diff --git a/packages/squiggle-lang/src/rescript/Utility/Sparklines.res b/packages/squiggle-lang/src/rescript/Utility/Sparklines.res index 12d509fa..72fcfc11 100644 --- a/packages/squiggle-lang/src/rescript/Utility/Sparklines.res +++ b/packages/squiggle-lang/src/rescript/Utility/Sparklines.res @@ -16,7 +16,7 @@ let create = (relativeHeights: array, ~maximum=?, ()) => { if E.A.length(relativeHeights) === 0 { "" } else { - let maximum = maximum->E.O2.default(E.A.max(relativeHeights)->E.O2.toExn("")) + let maximum = maximum->E.O2.default(E.A.Floats.max(relativeHeights)) relativeHeights ->E.A2.fmap(_heightToTickIndex(maximum)) diff --git a/packages/squiggle-lang/src/rescript/Utility/XYShape.res b/packages/squiggle-lang/src/rescript/Utility/XYShape.res index 1af36cf0..020acd42 100644 --- a/packages/squiggle-lang/src/rescript/Utility/XYShape.res +++ b/packages/squiggle-lang/src/rescript/Utility/XYShape.res @@ -60,8 +60,8 @@ module T = { module Ts = { type t = T.ts - let minX = (t: t) => t |> E.A.fmap(T.minX) |> E.A.min |> extImp - let maxX = (t: t) => t |> E.A.fmap(T.maxX) |> E.A.max |> extImp + let minX = (t: t) => t |> E.A.fmap(T.minX) |> E.A.Floats.min + let maxX = (t: t) => t |> E.A.fmap(T.maxX) |> E.A.Floats.max let equallyDividedXs = (t: t, newLength) => E.A.Floats.range(minX(t), maxX(t), newLength) let allXs = (t: t) => t |> E.A.fmap(T.xs) |> E.A.Sorted.concatMany } @@ -220,8 +220,8 @@ module XsConversion = { module Zipped = { type zipped = array<(float, float)> - let compareYs = ((_, y1), (_, y2)) => y1 > y2 ? 1 : 0 - let compareXs = ((x1, _), (x2, _)) => x1 > x2 ? 1 : 0 + let compareYs = ((_, y1): (float, float), (_, y2): (float, float)) => y1 > y2 ? 1 : 0 + let compareXs = ((x1, _): (float, float), (x2, _): (float, float)) => x1 > x2 ? 1 : 0 let sortByY = (t: zipped) => t |> E.A.stableSortBy(_, compareYs) let sortByX = (t: zipped) => t |> E.A.stableSortBy(_, compareXs) let filterByX = (testFn: float => bool, t: zipped) => t |> E.A.filter(((x, _)) => testFn(x))