Hacker News new | past | comments | ask | show | jobs | submit login

Two problems:

1. multi-line expressions aren't supported by the REPL.

2. You will need to use `let x = ..` syntax in the REPL (This is because the REPL are just so called IO-actions and the `let` syntax defines variables within its lexical scope)

You could try this:

    > let sieve (p:xs) =  p : sieve [x | x <- xs, x `mod` p /= 0]
    > let primes = sieve [2..]
    > primes !! 3
    > primes !! 4
Nice part abou this code is eventhough you express calculating ALL primes. It will only calculate upto the 3rd and the 4th prime due to lazy evaluation. This is one of the great strengths of haskell.



This online REPL does not support `let` either.

`let x = 4` is not an expression there.


At the online REPL, you have to write something like:

    let primes = sieve [2..] where sieve (p:xs) = p : sieve [x| x <- xs, x `mod` p /= 0] in primes
Which is rather annoying.


Not only that, but you have to do something like

    let primes = ... in take 5 primes
... if you want the computation to complete without hanging the browser. It would be nice if the REPL supported multi-line expressions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: