Infinite loop
starper opened this issue · comments
resize (const 0) $ genNonEmpty (pure unit)
will create an infinite loop by passing -1
to unfoldable
.
Since, as far as I understand, size
is not supposed to be less than 0, maybe it'll be a good idea to make it of type Natural?
No, because we don't have a non-negative integer type in the core libraries anywhere, and core libraries can't depend on non-core libraries. I think this is a bug in the relevant generator: any sized-based generator should treat negative sizes the same way as it treats zero.
Sorry, didn't notice that Natural
is not a part of core libraries. It would be nice to have it in core, btw, to eliminate a possibility for this kind of bugs to exist. Anyway, adding some kind of conditions to check if size >= 0
should obviously work, too =)
No worries :) the thing about Natural
is that it doesn't provide as much safety as we might hope it would, because of overflow and also because you can't safely implement subtraction (or at least, not while staying lawful with respect to the Ring
laws, so you'd need a separate subtraction operator, which makes it more awkward).
@hdgarrood thanks for explanation. So, as far as I understand the bug is that unfoldable
lacks a n < 0
pattern in this case expression, am I correct? Should I open a new issue for it?
I'm working on a fix now 🙂. Well, I've made the fix, but I'm setting up some tests too.
Oh, oops, sorry! I thought the relevant code was in a different library, I didn't realise which unfoldable
you were talking about.