From: pimjager Date: Thu, 14 Apr 2016 07:55:43 +0000 (+0200) Subject: Presentation X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=d0e8cca079e8b36453b3eeee66b25681e5423f18;p=cc1516.git Presentation --- diff --git a/deliverables/p2/p2.tex b/deliverables/p2/p2.tex index 0399d8d..09d75d2 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,92 @@ 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. + \pause + \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} + % - 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? diff --git a/examples/Markus/identity(2).spl b/examples/Markus/identity(2).spl index 96232a2..cba491c 100644 --- a/examples/Markus/identity(2).spl +++ b/examples/Markus/identity(2).spl @@ -12,34 +12,34 @@ id_int(x) :: Int -> Int id_poly_with(x) :: a -> a { return x; -} +}// -// Polymorphic identity without type signature -// Type checking should figure out the type forall a . a -> a -id_poly_without(x) -{ - return x; -} +//// Polymorphic identity without type signature +//// Type checking should figure out the type forall a . a -> a +//id_poly_without(x) +//{ +// return x; +//}// // Clumsy polymorphic identity // Type checking should give type forall a . a -> a -id_poly_wtf(x) +id_poly_wtf(x) :: a -> a { var a = x; var b = a; var c = b; return c; -} - - -// Clumsy identity for integers -// Type checking should give type Int -> Int -id_int_wtf(x) -{ - var a = x; - Int b = a; - var c = b; - return c; -} +}// + + +//// Clumsy identity for integers +//// Type checking should give type Int -> Int +//id_int_wtf(x) +//{ +// var a = x; +// Int b = a; +// var c = b; +// return c; +//} diff --git a/examples/Markus/multiple_recursion.spl b/examples/Markus/multiple_recursion.spl index 8676358..bfe6701 100644 --- a/examples/Markus/multiple_recursion.spl +++ b/examples/Markus/multiple_recursion.spl @@ -1,14 +1,10 @@ // Generates a list of zeros and ones -flip(n, l) -{ - if( n <= 0 ) - return l; - else - return flop(n-1, 0:l); +flip(n, l) :: Int -> [Int] -> [Int] { + if( n <= 0 ) {return l;} + else {return flop(n-1, 0:l);} } -flop(n, l) -{ +flop(n, l) { return flip(n, 1:l); } diff --git a/examples/example.spl b/examples/example.spl index 0bf275e..0387810 100644 --- a/examples/example.spl +++ b/examples/example.spl @@ -30,12 +30,12 @@ main ( ) :: Void { var ok = True; while(n<20) { facN = facR (n); - if (facN != factl (n) || facn != facL (n)){ + if (facN != factl (n) || facN != facL (n)){ print (n : facN : facl (n) : facL (n): []); ok=False; } } - print(ok); + //print(ok); } // A list based factorial function @@ -67,12 +67,12 @@ reverse(list):: [t] -> [t] { abs(n)::Int->Int{if(n<0)return -n; else return n;} //swap the elements in a tuple -swap(tuple) :: (a, a) -> (a, a){ - var tmp = tuple.fst; - tuple.fst = tuple.snd; - tuple.snd = tmp; - return tuple; -} +//swap(tuple) :: (a, a) -> (a, a){ +// var tmp = tuple.fst; +// tuple.fst = tuple.snd; +// tuple.snd = tmp; +// return tuple; +//} //list append append(l1, l2) :: [t] -> [t] -> [t] {