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

  • no go

    Two friends of mine were pretty enthusiastic about the Go language, so I tried writing a program in it yesterday. It is frustrating because despite…

  • playing with vala

    I actually was toying with making something like Vala back in college. It's pretty cute. Much like using the sane subset of C++, as you write code…

  • chromium.el

    This weekend I wrote some Emacs Lisp to write some utility functions I find useful for hacking on Chromium. It's fun to have a reason to use Lisp!…

  • 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