|
|
|
|
|
by Joker_vD
1221 days ago
|
|
let nums = take 10000000 naturals
print $ (sum nums, length nums)
> Because the nums list is used for both sum and length computations, the compiler can’t discard list elements until it evaluates both.Now that makes me wonder, if I write something like print $ (sum (take 10000000 naturals), length (take 10000000 naturals))
will it run in constant memory? I think it ought to, but are there mechanisms in GHC optimizer to prevent extraction of CSEs that would cause huge increases in memory consumption? |
|