Closed dubek closed 8 years ago
I think the real problem is that we currently fail to resize things like the call stack dynamically. If this is solved, it should not be much of a problem to have non-tail-recursive stuff.
The stacks are now resized on demand, so this problem is solved now. I can run (iota* 1 10000 1)
without problems. It still crashes when increasing the number to 100000, but this seems to be due to a limit of the C stack (at a point when it is about 50000 functions deep).
iota
is implemented withunfold
, which is not tail-recursive, and therefore segfaults if trying to generate long lists (300 elements on my machine).Or directly with
unfold
:One can make
unfold
tail-recursive withcat
instead ofcons
, but that will makeunfold
O(n^2), which we'd like to avoid. Not sure if there's a way to makeunfold
tail-recursive, or to useunfoldr
foriota
(for example useunfoldr
and thenreverse
).