Add pattern matching on MaybeInt
This commit is contained in:
parent
81170661bc
commit
40fb30148f
12
VL1.tex
12
VL1.tex
@ -520,6 +520,18 @@ calcSomething x
|
|||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
\end{frame}
|
\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]
|
\begin{frame}[fragile]
|
||||||
\frametitle{Algebraic Data Types (ctn.)}
|
\frametitle{Algebraic Data Types (ctn.)}
|
||||||
Let's define something more complex. How about a tree?
|
Let's define something more complex. How about a tree?
|
||||||
|
Loading…
Reference in New Issue
Block a user