Переглянути джерело

Add pattern matching on MaybeInt

stripped-german
Julian Ospald 9 роки тому
джерело
коміт
40fb30148f
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 220CD1C5BDEED020
1 змінених файлів з 12 додано та 0 видалено
  1. +12
    -0
      VL1.tex

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


Завантаження…
Відмінити
Зберегти