Course map
Haskell // 01

Values and types

Read

Everything has a type

A Haskell program is built from values: numbers, text, booleans, lists. Every value has a type, and you can write the type down with two colons.

answer :: Int
answer = 42

greeting :: String
greeting = "hello, miso"

ready :: Bool
ready = True

pi' :: Double
pi' = 3.14159

Read answer :: Int as answer has type Int. The second line gives the value. A value never changes once defined: answer is 42 for the whole program.

The compiler checks that every value is used at its type. Add an Int to a String and the program is rejected before it ever runs. That is the deal Haskell offers: a little more thinking up front, far fewer surprises later.

01 / 05