get first element of list haskell code example
Example 1: first element in list haskell
list = [1, 2, 3]
head :: [a] -> a
head (x:_) = x
head list -- 1
Example 2: remove first element list haskell
a = [1, 2, 3, 4]
b = tail a
-- b == [2, 3, 4]
Example 3: haskell append to list
1 : [2, 3]
--return [1, 2, 3]
Example 4: haskell list element at index
-- the "!!" operator return the n-th element from the list
-- *this is zero based
"string" !! 2 --> "r"
[10, 20, 30, 40] !! 1 --> 20