Skip to content
Variables and Types
step 1/5

Reading — step 1 of 5

Learn

~1 min readGetting Started

In Haskell, variables don't vary — once bound, a name can't be reassigned. There's no mutation in pure code (mutation requires IORef in IO).

name :: String
name = "Alice"

age :: Int
age = 30

-- Inside a function: let or where
greeting = let n = "Bob"
               a = 25
           in "Hi " ++ n

Basic types:

  • Int, Integer (Integer is arbitrary-precision)
  • Double, Float
  • Bool (True / False)
  • Char, String (which is [Char] — a list of characters)

Type signatures use ::. Function types use ->: add :: Int -> Int -> Int is "a function taking two Ints and returning an Int". (The -> is right-associative — really it's Int -> (Int -> Int) — but more on that later.)

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…