Skip to content
Lesson 2 of 15

Step 1 of 5 · Reading · ~1 min

Learn

Getting 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.)

Up nextNumbers and MathGetting Started

Discussion

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

Sign in to post a comment or reply.

Loading…