Contents

1 Overview

Haskell is a functional (that is, everything is done with function calls), statically, implicitly typed (types are checked by the compiler, but you don't have to declare them), lazy (nothing is done until it needs to be) language. Its closest popular relative is probably the ML family of languages.

You can build with ghc --make Test.hs, and the result will be called Test. (On Windows, Test.exe) You get an

if

expression as a bonus.
Every line that starts in the same column as the first

putStrLn

is part of the

do

block. This is called "layout", and Haskell uses it to avoid making you put in statement terminators and braces all the time. (The

then

and

else

phrases have to be indented for this reason: if they started in the same column, they'd be separate statements, which is wrong.)

(Note: Do not indent with tabs if you're using layout. It technically still works if your tabs are 8 spaces, but it's a bad idea.)

4 Simple types

So far, not a single type declaration has been mentioned. That's because Haskell does type inference. You generally don't have to declare types unless you want to. If you do want to declare types, you use

::

to do it.
Prelude>

5::Int

5

Prelude>

5::Double

5.0

Types (and type classes, discussed later) always start with upper-case letters in Haskell. Variables always start with lower-case letters. This is a rule of the language, not a naming convention.

You can also ask ghci what type it has chosen for something. This is useful because you don't generally have to declare your types.