X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=deliverables%2Fp2%2Fp2.tex;h=a3fca20f9598cffe0fa94e09a6b7311cd79ef977;hb=158fb0cf298aaae42c8460f92bb7d797d5def9bd;hp=0399d8d51fde04146bc252dd7464d802bfc3e08c;hpb=5f216c089cf607cab359f5bc8d5b4ec76bc15a25;p=cc1516.git diff --git a/deliverables/p2/p2.tex b/deliverables/p2/p2.tex index 0399d8d..a3fca20 100644 --- a/deliverables/p2/p2.tex +++ b/deliverables/p2/p2.tex @@ -67,6 +67,11 @@ sem :: AST -> SemOutput \pause% \begin{block}{Order?} Does matter for variables, not for functions. + \pause + \begin{itemize} + \item Note that this means that \texttt{ones=1:ones} is + not allowed. + \end{itemize} \end{block} \pause% \begin{block}{Mutual recursion?} @@ -74,10 +79,121 @@ sem :: AST -> SemOutput \end{block} \pause% \begin{block}{Higher order functions?} - Hopefully in the future + Would be an interesting idea for assignment 4 \end{block} \end{frame} +\begin{frame}[fragile] + \frametitle{Mutual Recursion} + \begin{itemize} + \item Mutual recursion is allowed and type checked, however inference is + not complete. + \pause + \begin{CleanCode} +flip(n, l) :: Int -> [Int] -> [Int] { + if( n <= 0 ) {return l;} + else {return flop(n-1, 0:l);} +} + +flop(n, l) :: Int -> [Int] -> [Int] { + return flip(n, 1:l); +} + \end{CleanCode} + \pause + \item Completely typed specifications are checked correctly. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Mutual Recursion} + \begin{itemize} + \item Mutual recursion is allowed and type checked, however inference is + not complete. + \begin{CleanCode} +flip(n, l) :: Int -> [Int] -> [Int] { + if( n <= 0 ) {return l;} + else {return flop(n-1, 0:l);} +} + +flop(n, l) :: Int -> [Int] -> Bool { + return flip(n, 1:l); +} + \end{CleanCode} + \pause + \item It is also correctly determined that \texttt{Bool} and the return + type of \texttt{flop(n,l)} don't match. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Mutual Recursion} + \begin{itemize} + \item Mutual recursion is allowed and type checked, however inference is + not complete. + \begin{CleanCode} +flip(n, l) { + if( n <= 0 ) {return l;} + else {return flop(n-1, 0:l);} +} + +flop(n, l) { + return flip(n, 1:l); +} + \end{CleanCode} + \end{itemize} +\end{frame} + + +\begin{frame}[fragile] + \frametitle{Mutual Recursion} + \begin{itemize} + \item Mutual recursion is allowed and type checked, however inference is + not complete. + \begin{CleanCode} +flip(n, l) :: Int -> [Int] -> vTqhp { + if( n <= 0 ) {return l;} + else {return flop(n-1, 0:l);} +} + +flop(n, l) :: Int -> [Int] -> HSWdn { + return flip(n, 1:l); +} + \end{CleanCode} + \item However when no type information is given at all our algorithm + fails to correctly infer the result type of the two function. + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{But wait, there is more!} + \framesubtitle{Trouble that is} + \begin{itemize} + \item Polymorphism is not working great either. + \begin{CleanCode} +id(x) :: a -> a { + return x; +} + \end{CleanCode} + \pause + \item Is typed fun, but when we introduce: + \begin{CleanCode} +var x = id(5); +var y = id(True); + \end{CleanCode} + \pause + \begin{CleanCode} +2:12 SemError: Cannot unify types. Expected: Int. Given: Bool + \end{CleanCode} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{But wait, there is more!} + \framesubtitle{Trouble that is} + + \begin +\end{frame} + % - Can functions that are defined later in a file call earlier defined functions? % - Can local variables be defined in terms of other local variables? % - How do you deal with assignments?