Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

23 Zeilen
1.1 KiB

  1. Let's define something more complex. How about a tree?
  2. \pause
  3. \begin{haskellcode}
  4. data Tree = Leaf Char
  5. | Node Tree Int Tree
  6. \end{haskellcode}
  7. Uh... that looks mean. Let's examine this.\\
  8. \pause
  9. We have:
  10. \begin{itemizep}
  11. \item defined a data type \hinline{Tree}
  12. \item a constructor \hinline{Leaf} of type \hinline{Tree} with one arguments of type \hinline{Char}
  13. \item a constructor \hinline{Node} of type \hinline{Tree} with 3 arguments
  14. \begin{itemizep}
  15. \item \hinline{Tree}
  16. \item \hinline{Int}
  17. \item \hinline{Tree}
  18. \end{itemizep}
  19. \end{itemizep}
  20. \slidep
  21. That means: a \hinline{Tree} can either be a \hinline{Leaf} or an internal \hinline{Node} with two sub-trees. If we want to create a \hinline{Leaf}, we have to pass the constructor a \hinline{Char}. If we want to create a \hinline{Node}, we have to pass 3 arguments, in order: another \hinline{Tree}, an \hinline{Int} and yet another \hinline{Tree}.\\
  22. So we can save information in the leafs (\hinline{Char}) and in the internal nodes (\hinline{Int}).\\
  23. This is just an example. There are endless more ways of trees.