You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

20 lines
745 B

  1. 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:
  2. \begin{haskellcode}
  3. data WeekDay = Monday
  4. | Tuesday
  5. | Thursday
  6. | Wednesday
  7. | Friday
  8. | Saturday
  9. | Sunday
  10. \end{haskellcode}
  11. This declares the new data type \hinline{WeekDay} with 7 \emph{constructors}. That means \hinline{Monday}, \hinline{Tuesday} etc. are all values of the type \hinline{WeekDay}.
  12. \pause
  13. \\
  14. We could now define a whole week, by creating a list:
  15. \pause
  16. \begin{haskellcode}
  17. week :: [WeekDay]
  18. week = [Monday, Tuesday, Thursday, Wednesday
  19. , Friday, Saturday, Sunday]
  20. \end{haskellcode}