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

I'm new to Haskell, and I like this page. So, wanting to get a feel for it, I tried typing the sieve example from the top of the page into the "Type Haskell expressions in here." box right beneath it.

First, I got

    <hint>:1:8: parse error on input `='
Hm so apparently definitions aren't expressions? Or something?

I decided to remove the `primes = ` part, which made my browser really slow and had no result. I'm assuming it was computing all primes in the background.

Now, of course, maybe I should try to understand the sieve example before running it, but isn't the whole point of having a REPL box on the front page that you can facilitate people who learn the other way around? It would be great if there'd be some code or expressions available at my fingertips that would actually work in that REPL.

In other words, maybe make the first example be something that actually terminates?

Please read this as constructive criticism, which is how it is intended.

EDIT: Only now I'm noticing that exactly the things I ask for are listed to the right of the "try" box. Pardon my lazy reading, I'm really enjoying the tutorial right now. Still, making the `sieve` example terminate would be nice. But I believe my nitpick is maybe a bit much of a nitpick now.




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.


The biggest problem isn't what others have said. The biggest problem is that the try box doesn't let you define your own functions or variables.

Therefore, even if you were an old hand at GHC and GHCi and so on, you'd still be unable to run the code it shows at the top of the page.

This is probably bad website design. Especially since the website still lets randoms burn themselves by entering non-terminating code that makes their browsers slow.


The code doesn't run in-browser. It runs in a sandboxed environment elsewhere.


I agree with the problems but am curious how you would solve the non-terminating code problem?


> I agree with the problems but am curious how you would solve the non-terminating code problem?

I thought it was running on the browser, based on what the OP said, so that would entail opcode-counting or, if you can use multiple threads, watchdog timers. That is, don't try to solve the halting problem, just enforce an arbitrary limit to how long code can run.

However, if the code is being run on the server, you could enforce CPU and RAM quotas to do the same thing with the OS's help.


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


In a normal ghci repl, you would be able to use the syntax "let name = expr", but this repl doesn't seem to support that.

My best guess is that it's because it's implemented as an HTTP service that happens not to retain the ghci process between expressions.


You need to check syntax, or try some more basic examples first. In this case you pasted piece of code that won't work itself.

If you want to get know more about it: http://learnyouahaskell.com/syntax-in-functions


Sure, but my point is that maybe the top example should be one that'd work verbatim in the REPL, to not scare noobs like me away.


Yeah, the REPL story's a bit of a mess, but Haskellers tend to forget that.


Just to mention it here, IHaskell solves a lot of the annoyances with ghci. Easy multi-line input, don't need let in front of functions, can define modules and load them (automatically compiled), etc. I think they are working on support for template haskell too (important for experimenting with lens code etc)


Oops, I missed that. Indeed example is not REPL ready.


I totally agree with you.




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

Search: