From 40fb30148f1cd86f47a97441b1b9d9d98a128a5e Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Thu, 16 Apr 2015 01:31:42 +0200 Subject: [PATCH] Add pattern matching on MaybeInt --- VL1.tex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/VL1.tex b/VL1.tex index 51b3196..1a00127 100644 --- a/VL1.tex +++ b/VL1.tex @@ -520,6 +520,18 @@ calcSomething x \end{lstlisting} \end{frame} +\begin{frame}[fragile] +\frametitle{Algebraic Data Types (ctn.)} +And pattern match on it as well: +\setHaskellCodeStyle +\begin{lstlisting} +addIntToList :: MaybeInt -> [Int] +addIntToList (NoError x) = [x] +addIntToList (Error str) = [] +\end{lstlisting} +So if we got an error, we just return an empty list, otherwise we return a list with the \code{Int} as its only element. +\end{frame} + \begin{frame}[fragile] \frametitle{Algebraic Data Types (ctn.)} Let's define something more complex. How about a tree?