diff --git a/VL2/content/VL2_polymorphism1.tex b/VL2/content/VL2_polymorphism1.tex index d8c8bc3..292ebd8 100644 --- a/VL2/content/VL2_polymorphism1.tex +++ b/VL2/content/VL2_polymorphism1.tex @@ -2,19 +2,4 @@ So when we said that haskell is good for abstraction, what did we actually mean? \vspace{\baselineskip} \\ \pause -Even better! Haskell supports polymorphism for both data types and functions.\\ -Let's start with a polymorphic data type: -\begin{haskellcode} -data List t = Empty | Cons t (List t) -\end{haskellcode} -So we just implemented our own singly-linked List. For any type! Let's use it: -\pause -\begin{haskellcode} -intList :: List Int -intList = Cons 3 (Cons 5 (Cons 2 Empty)) - -charList :: List Char -charList = Cons 'x' (Cons 'y' (Cons 'z' Empty)) - --- whatever you can imagine goes here -\end{haskellcode} \ No newline at end of file +Even better! Haskell supports polymorphism for both data types and functions. \ No newline at end of file diff --git a/VL2/content/VL2_polymorphism2.tex b/VL2/content/VL2_polymorphism2.tex index d849230..0955531 100644 --- a/VL2/content/VL2_polymorphism2.tex +++ b/VL2/content/VL2_polymorphism2.tex @@ -1,20 +1,19 @@ -And now we are going to write functions to use it: -\begin{haskellcode} -isListEmpty :: List t -> Bool -isListEmpty Emtpy = True -isListEmpty x = False -\end{haskellcode} -\pause -We can even have more generic stuff like: -\begin{haskellcode} -f :: a -> b -\end{haskellcode} -Whatever the function does... it has something of one type and returns something of another type (it could be the same type, but doesn't need to). That's all we know. -\vspace{\baselineskip} -\\ -\pause -Similarly, remember the function \hinline{head} which gives us the first element of a list? The type signature actually looks like this: +Let's start with a polymorphic function that you already know: \begin{haskellcode} head :: [a] -> a \end{haskellcode} -Makes sense? \ No newline at end of file +\pause +So \hinline{head} takes a list of any type and returns an element which must have the \emph{exact same} type of that list. +\vspace{\baselineskip} +\\ +\pause +We can also have: +\begin{haskellcode} +f :: a -> b +\end{haskellcode} +\pause +So, whatever the function does... it has something of one type and returns something of another type. \hinline{b} \emph{could} be the same type as \hinline{a} here, but it doesn't need to! That's all we know about this function. +\vspace{\baselineskip} +\\ +\pause +You don't have to use \hinline{a} or \hinline{b} here. These letters are just commonly used for generic types. \ No newline at end of file diff --git a/VL2/content/VL2_polymorphism3.tex b/VL2/content/VL2_polymorphism3.tex deleted file mode 100644 index e69de29..0000000