Haskell for the Evil Genius
yellosoft.us
yellosoft.us
main = let fib 30 = 832040 in do
putStrLn (show (fib 30))
This is not what I would normally consider 'lazy' or 'memoization'...Not to be too pedantic but that 'sieve' is also not really the sieve of Eratosthenes either, as it continually recomputes each slot:
In GHCI, trying that example with fib 29 results in a non exhaustive pattern error.
let 2+2=5 in 2+2
amusingly returns 5. Prelude> let 2+2=5 in 2+3
*** Exception: <interactive>:1:5-9: Non-exhaustive patterns in function + Prelude> let (+) 2 2 = 5; 4 + 2 = 42 in [2 + 2, (+) 4 2, 0 + 3]
[5,42,*** Exception: <interactive>:1:5-29: Non-exhaustive patterns in function +
Prelude> let fib 0 = 1 in fib 0
1I didn't notice the errors but having people at HN showing me what is wrong helped me learn more about Haskell. I hope that pointing those errors helps make the post more robust, too.
(not sure if this is true, perhaps GHC is smart about it).
If nothing else, superfluous derives would seem to distract/obfuscate your intent.