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
664 B

  1. So when we said that haskell is good for abstraction, what did we actually mean? Do we have something like java generics or C++ templates?
  2. \vspace{\baselineskip}
  3. \\
  4. \pause
  5. Even better! Haskell supports polymorphism for both data types and functions.\\
  6. Let's start with a polymorphic data type:
  7. \begin{haskellcode}
  8. data List t = Empty | Cons t (List t)
  9. \end{haskellcode}
  10. So we just implemented our own singly-linked List. For any type! Let's use it:
  11. \pause
  12. \begin{haskellcode}
  13. intList :: List Int
  14. intList = Cons 3 (Cons 5 (Cons 2 Empty))
  15. charList :: List Char
  16. charList = Cons 'x' (Cons 'y' (Cons 'z' Empty))
  17. -- whatever you can imagine goes here
  18. \end{haskellcode}