20 lines
733 B
TeX
20 lines
733 B
TeX
![]() |
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}
|
||
|
This declares the new data type \code{WeekDay} with 7 \emph{constructors}. That means \code{Monday}, \code{Tuesday} etc. are all values of the type \code{WeekDay}.
|
||
|
\pause
|
||
|
\\
|
||
|
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}
|