Creating New Variables

Haskell variables must start with a lowercase letter and can contain letters, numbers, underscores, and the single quote character (‘). You can use Unicode letters in Haskell variable names, but we’ll stick to ASCII in this book. By convention, Haskell variables use camelCase. Here are some examples:

 helloWorld = ​"Hello, World"
 number5 = 5
 snake_case_variable = ​True
 number5' = 6

As you might expect, we can also assign a variable to another variable:

 five = 5
 number = five

In ghci you can enter the name of a variable to see its value:

 λ​ helloGeorge = ​"Hello, George"
 λ​ helloGeorge
 "Hello, George"
 λ​ five = 2 + 3
 λ​ five
 5

You can also re-use a variable name in ghci. For example, let’s create ...

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.