Are sequences of elements of the same type, which are written enclosed in square parenthesis and separated by commas.

Due to lazy evaluation in Haskell there is no requirement that lists have finite length.

The type of a list is written [T] when elements are of type T.

One can add elements to a list using the cons operator : by prepending a new element to the start of an existing list. Lists are actually defined by the cons operator, such that [1,2,3] is really an abbreviation for 1:(2:(3:[])).

Lists of integers incremented by 1 from start to end can be defined by [start..end]. If end is omitted then the list is infinite.

Strings are defined as lists of chars, such that "abc" :: String is just an abbreviation for ['a', 'b', 'c'] :: [Char]. Therefore any polymorphic function on lists can also be used with strings.

Examples

Type

[False, True, False] :: [Bool]
[['a', 'b'], ['c', 'd', 'e']] :: [[Char]]

Prepending

> 1 : [2,3]
[1,2,3]

Creating list of integers in interval

> [1..3]
[1,2,3]

Strings as list of chars

> "abcde" !! 2
’c’
 
> take 3 "abcde"
"abc"
 
> length "abcde"
5
 
> zip "abc" [1,2,3,4]
[(’a’,1),(’b’,2),(’c’,3)]