In Haskell, the following code prints "[1,2,3,4,5":
foo = take 10 $ show $ numbersFrom 1 where
numbersFrom start = start : numbersFrom (start + 1) -- could use [1..]
But in Frege, It throws OutOfMemoryError
with the following code:
foo = take 10 $ unpacked $ show $ numbersFrom 1 where
numbersFrom start = start : numbersFrom (start + 1)
Here the only difference is the unpacked
function which is necessary to convert from String
to [Char]
and FWIW, the unpacked
function is eager. Why can't the whole expression be lazy as in Haskell? Is it possible to achieve something similar to Haskell in Frege here?
I haven’t used Frege, but it seems to me that if
unpacked
is strict, then its argument ought not be an infinite list. Tryunpacked $ take 10
instead oftake 10 $ unpacked
.