haskell-lectures/VL1/content/VL1_lists1.tex
Julian Ospald f36590c9f4
Restructure files, make the latex code more modular
Also added a few more section to make beamer and article more
compatible.
2015-04-20 17:38:58 +02:00

22 lines
749 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 \code{[]} notation:
\begin{haskellcode}
list1 :: [Integer]
list1 = [1, 2]
\end{haskellcode}
\pause
or by using the \emph{cons} operator \code{(:)} 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}