haskell-lectures/VL1/content/VL1_ADT1.tex

20 line
1.1 KiB
TeX

\ifger{Natürlich können wir auch unsere eigenen Datentypen definieren. Ein sehr häufiger Typ ist die \emph{Enumeration}. Z.b. können wir den Wochentag definieren als:}{Of course we can also define our own data types in haskell. One very common type is the \emph{enumeration}. For example, we could define a data type for the Week:}
\begin{haskellcode}
data WeekDay = Monday
| Tuesday
| Thursday
| Wednesday
| Friday
| Saturday
| Sunday
\end{haskellcode}
\ifger{Dies erzeugt den neuen Datentyp}{This creates the new data type} \hinline{WeekDay} \ifger{mit}{with} 7 \emph{\ifger{Konstruktoren}{constructors}}. \ifger{Das bedeutet, dass}{That means} \hinline{Monday}, \hinline{Tuesday} etc. \ifger{alles Werte vom Typ}{are all values of the type} \hinline{WeekDay}\ifger{ sind.}{.}
\pause
\\
\ifger{Jetzt können wir auch eine ganze Woche definieren mittels einer Liste:}{We could now define a whole week, by creating a list:}
\pause
\begin{haskellcode}
week :: [WeekDay]
week = [Monday, Tuesday, Thursday, Wednesday
, Friday, Saturday, Sunday]
\end{haskellcode}