You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gen.elements only returns first or last element. #22
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.
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.
If I switch the order of elements g and f in the type class instance, the distribution is more even. The index lookup is done from the back (so calling it with 0 gets the last element). Negative numbers still cause the same crash.
instancesemigroupAtIndex :: Semigroup (AtIndexa) where
append (AtIndex g) (AtIndex f) = AtIndex \i ->if i <= 0then f i else g (i - 1)
I think we could do with some distribution tests, maybe in quickcheck if not here. I've definitely seen a few cases (separate from this one) where quickcheck is giving an odd distribution of results.
Activity
niklas commentedon Jun 3, 2020
If I switch the order of elements
gandfin the type class instance, the distribution is more even. The index lookup is done from the back (so calling it with0gets the last element). Negative numbers still cause the same crash.garyb commentedon Jun 3, 2020
You need to use parens around the negative number,
-10is an expression rather than a literal.What type are you using for your
MonadGeninstance, maybe the poor distribution is down to that?garyb commentedon Jun 3, 2020
Hmm, no, I see it too. That's extremely concerning that it's been like this for a long time!
hdgarrood commentedon Jun 3, 2020
I think we could do with some distribution tests, maybe in quickcheck if not here. I've definitely seen a few cases (separate from this one) where quickcheck is giving an odd distribution of results.
garyb commentedon Jun 3, 2020
Yeah, I reproduced this by adding a test case. I thought this library had better test coverage than it does.
Fix genDate generator frequency
Fix genDate generator frequency