01 02 03 04 05 06 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 ← →
module Main where
Lists are arbitrary length sequences of elements of the same type. The
operator (:)
prepends an element to a list. The operator (++)
concatenates
two lists. The operator (!!)
selects an element of a list, counting from
zero. length
returns the length of a list.
(:) ∷ a → [a] → [a] (++) ∷ [a] → [a] → [a] (!!) ∷ [a] → Int → a length ∷ [a] → Int
ends ∷ [a] → [a] ends x = [ x !! 0, x !! (length x - 1) ] y ∷ [Int] y = 1 : [2,3] ++ [4,5] main ∷ IO () main = mapM_ print [y, ends y]
[1,2,3,4,5] [1,5]