haskell-lectures/VL1/content/VL1_lists1.tex

22 lines
755 B
TeX

The list is probably the most basic data structure in Haskell. Like the array in C. It is a singly-linked list and is very lazy. The compiler has numerous ways to optimize lists, so don't be afraid to use them, even for huge things.
\pause
We build lists by using either the \hinline{[]} notation:
\begin{haskellcode}
list1 :: [Integer]
list1 = [1, 2]
\end{haskellcode}
\pause
or by using the \emph{cons} operator \hinline{(:)} which takes an element and a list and produces a new list with the element prepended to the front.
\begin{haskellcode}
emptyList = []
list2 = 1 : []
-- is this really a list?
list3 = [1, 2] == 1 : 2 : []
\end{haskellcode}
\pause
How about something more interesting:
\begin{haskellcode}
infiniteList = [1..]
\end{haskellcode}