haskell-lectures/VL1/content/VL1_lists1.tex

22 行
1.2 KiB
TeX

\ifger{Die Liste ist vermutlich der grundlegendste Datentyp in Haskell, ähnlich wie das Array in C. Sie ist singly-linked und lazy. Der Compiler beherrscht viele Tricks, die Liste zu optimieren, deshalb kann man sie auch für komplexere Probleme benutzen.}{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
\ifger{Wir erzeugen Listen entweder mit der}{We build lists by using either the} \hinline{[]} \ifger{Notation:}{notation:}
\begin{haskellcode}
list1 :: [Integer]
list1 = [1, 2]
\end{haskellcode}
\pause
\ifger{oder mit dem}{or by using the} \emph{cons} \ifger{Operator}{operator} \hinline{(:)} \ifger{welcher ein Element nimmt und es an den Anfang einer Liste setzt und somit eine neue Liste erzeugt.}{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
\ifger{Wie wäre es mit etwas interessanterem:}{How about something more interesting:}
\begin{haskellcode}
infiniteList = [1..]
\end{haskellcode}