Evan Martin (evan) wrote in evan_tech,
Evan Martin

haskell getting started

Two people have asked me about this recently, so:

One hurdle for learning Haskell is that it seems like all of the code you find online doesn't work when you type it into the interpreter.

This is because (unfortunately, though probably for good reasons that aren't apparent to me) Haskell programs are typically a collection of definitions and the REPL only evaluates expressions. So 2 * 2 works fine but x = 2 * 2 doesn't.

Instead, you have to make a file. I then use ghci foo.hs to load it into the REPL, where you can write main to run it or any other expression to test code. And to just run a file directly, use runhaskell foo.hs .

(PS: I lied in the above. It's actually that everything given at the prompt is interpreted within the IO monad. So you can do let x = 2 * 2 in the REPL, but this is a confusing way to get started, because the syntax is different than normal code.)
Tags: haskell

  • more on bug tracking; distributed editing

    A few separate posts, all in the same area. 1) Most (all?) the distributed bug tracking software I've glanced at stores bugs in a directory, one…

  • dvcs and offline

    I got a couple of comments on that previous post that betray a bit of a misunderstanding about how collaborative projects work in the presence of…

  • distributed bug tracking

    Distributed bug tracking is the natural extension of distributed version control. Aside from the normal benefits of distributed version control, like…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.