Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

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
Subscribe

  • blog moved

    As described elsewhere, I've quit LiveJournal. If you're interested in my continuing posts, you should look at one of these (each contains feed…

  • dremel

    They published a paper on Dremel, my favorite previously-unpublished tool from the Google toolchest. Greg Linden discusses it: "[...] it is capable…

  • treemaps

    I finally wrote up my recent adventures in treemapping, complete with nifty clickable visualizations.

  • Post a new comment

    Error

    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.
  • 3 comments