Add pattern matching on MaybeInt

This commit is contained in:
Julian Ospald 2015-04-16 01:31:42 +02:00
父節點 81170661bc
當前提交 40fb30148f
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 220CD1C5BDEED020
共有 1 個檔案被更改,包括 12 行新增0 行删除

12
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?