Closed
Description
I ran into a problem with Gen.elements
. No matter how often I use it with a Random Generator, it always gives me either the first or the last element of the Foldable1 f
.
My suspicion is the internal helper fromIndex
:
edge cases seem to work
fromIndex 0 $ 10 :| [20,30,40,50,60] -- 10
fromIndex 10 $ 10 :| [20,30,40,50,60] -- 60
but indices within the bounds don't
fromIndex 5 $ 10 :| [20,30,40,50,60] -- 60
fromIndex 1 $ 10 :| [20,30,40,50,60] -- 60
given a negative index, the function crashes for me
fromIndex -10 $ 10 :| [20,30,40,50,60]
Error found:
in module $PSCI
at :1:12 - 1:14 (line 1, column 12 - line 1, column 14)
Could not match type
Int
with type
Int -> t0 t1 -> t1
while checking that type Int
is at least as general as type Int -> t0 t1 -> t1
while checking that expression 10
has type Int -> t0 t1 -> t1
in value declaration it
where t1 is an unknown type
t0 is an unknown type
I am still new to Purescript, so I am not sure why a negative Int
can cause that.
Luckily, it won't be called with negative numbers as long the provided chooseInt
behaves correctly. Nonetheless, above behavior would explain the the uneven distribution of elements
.
Metadata
Metadata
Assignees
Labels
No labels