Lesson 9 of 16
Lists
Lists
Lists are Haskell's fundamental data structure. All elements must have the same type.
let nums = [1, 2, 3, 4, 5]
let greets = ["hello", "world"]
Ranges
Use [a..b] to generate a range:
[1..5] -- [1,2,3,4,5]
[2,4..10] -- [2,4,6,8,10]
Basic Functions
head [1,2,3] -- 1
tail [1,2,3] -- [2,3]
length [1,2,3] -- 3
null [] -- True
null [1] -- False
Cons Operator (:)
: prepends an element to a list:
1 : [2, 3] -- [1,2,3]
0 : [1..4] -- [0,1,2,3,4]
Your Task
Create the list [1..10] and print:
- Its length
- Its head
- Its last element using
last
Haskell loading...
Loading...
Click "Run" to execute your code.