Lesson 2 of 16

Variables

Variables in Haskell

In Haskell, variables are immutable bindings. Once bound, a value never changes. You bind values inside a do block using let:

main :: IO ()
main = do
  let name = "Alice"
  let age = 30
  putStrLn name
  print age

Types

Haskell is statically typed. Common types:

ValueType
42Int
3.14Double
"hello"String
TrueBool

You can optionally annotate types:

let x :: Int
    x = 42

show

show converts any showable value to a String:

putStrLn (show 42)   -- "42"

Your Task

Bind name to "Haskell" and year to 1990, then print them each on their own line using putStrLn and show.

Haskell loading...
Loading...
Click "Run" to execute your code.