[Haskell-cafe] Tutorial uploaded

Paul Moore p.f.moore at gmail.com
Tue Dec 20 09:39:22 EST 2005


On 12/20/05, Daniel Carrera <daniel.carrera at zmsl.com> wrote:
> Hi all,
>
> I've finished a first draft of what I call "First steps in Haskell".
> It's intended to be the very first thing a new user sees when they
> decide to try out Haskell.
>
> http://www.haskell.org/hawiki/FirstSteps?action=show
>
> It's a bit longer than I'd like, but I don't inmediately see anything I
> can take out without losing something valuable (given the purpose of
> this document).
>
> Thoughts and comments?

It looks very good. The length isn't a problem to me, if anything I'd
be happy expanding a little.

One thing I'd consider adding is something along the lines of a section:

------------------------------------------------------------------------------------

== So how do I write "Hello, world"? ==

Well, the first thing you need to understand that in a functional
language like Haskell, this is a harder question than it seems. Most
of the code you will write in Haskell is "purely functional", which
means that it returns the same thing every time it is run, and has no
side effects. Code with side effects is referred to as "imperative",
and is carefully isolated from functional code in Haskell.

To deal with the distinction between functional and imperative code,
Haskell uses a construct called the "IO monad". It's not hard to
understand - basically, it's just a way of "wrapping up" imperative
code so that there's a clear boundary between it and functional code -
but most tutorial presentations of Haskell start with functional code,
and introduce the IO monad later.

As a taster, though, here is "Hello, world" in Haskell:

{{{
module Main where

main :: IO ()
main = putStrLn "Hello, World!"
}}}

Put this in a file called hello.hs, and compile it with `ghc -make
hello.hs -o hello`. You'll get an executable called hello (or
hello.exe on Windows). Run it to see the output.

There will be plenty more on writing standalone programs, IO, and
other aspects of the IO monad, as you learn more about Haskell.

------------------------------------------------------------------------------------

The point is, people *will* want to write "hello, world", so don't put
them off by making it seem "hard". Show them how, explain where they
will find out more, and explain why things like this come naturally at
a later stage when learning Haskell than they do with, say, C.

Paul.


More information about the Haskell-Cafe mailing list