Re:The New Haskell.org
by shangaslammi on Sunday February 15, 2015 @12:07PM
(#9053189)
Yeah, the online REPL is definitely not very useful or intuitive yet.
As it says, you can evaluate a single line Haskell "expression" and top-level declarations (like the sieve example) are not expressions. In addition, the sieve example declares an infinite list so there's no sensible way to print it.
You can fix all the above by using a let-expression on single line and only evaluating a finite part of the list using the 'take' function.
let { primes = sieve [2..]; sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0] } in take 10 primes
As it says, you can evaluate a single line Haskell "expression" and top-level declarations (like the sieve example) are not expressions. In addition, the sieve example declares an infinite list so there's no sensible way to print it.
You can fix all the above by using a let-expression on single line and only evaluating a finite part of the list using the 'take' function.