Haskell basics: what the language is and where it is used
What Haskell is
Haskell is a purely functional language with a type system that
catches whole classes of bugs before the program starts. A function
cannot quietly reach into the outside world, a missing case in a
pattern match is a warning, and a value that may be absent has a
type that says so.
The language dates from 1990 and shaped what later languages borrow:
type classes, immutable data, lazy evaluation, and the do notation
that hides sequencing behind a readable block. There is no null: a
missing value is a Maybe, and the compiler
makes you handle it.
Where it is used
Haskell is strong where correctness matters more than a quick first
draft: compilers and language tools, financial modelling, data
pipelines, configuration and network services. Cardano and many
industrial trading systems are written in it, and GHC itself is
written in Haskell.
A background in any strict language helps, see
Development for the neighbouring courses. The
language is a good second language precisely because it makes
different choices: no mutation, no statements, and functions as
ordinary values.
Hello, world
A Haskell program is a set of definitions, and the runtime calls main. Put this in a file Hello.hs:
main :: IO ()
main = putStrLn "Hello, world!"
Run it with the interpreter, which needs no build step:
runghc Hello.hs
Hello, world!
The same file compiles to a native binary:
ghc Hello.hs
[1 of 1] Compiling Main ( Hello.hs, Hello.o ) Linking hello ...
IO () is the type of an action: it may talk to the world and returns nothing useful. A function without IO in its signature cannot print, read a clock, or change a global variable, which is what makes the rest of the program easy to test.
The course
The full course is fifty lessons, from this first program to a working command line tool: Haskell course: zero to hero in 50 lessons. Every page ends with a link to the next one.
Article author: Arthur Isaev