CSc 372 - Comparative Programming Languages
10 : Haskell -- Polymorphic Functions

Christian Collberg

Department of Computer Science

University of Arizona

1 Polymorphic Functions

2 Polymorphic Functions...

3 Polymorphic Functions...

4 Polymorphic Functions...


Context Predicates


5 The remdups Function


\begin{gprogram}
remdups :: [Int] -> [Int] \\
remdups x:y:xs = \\
\x if x == y...
...arrow$\ case 2 \\
remdups xs = xs \xxxxxxxx $\Leftarrow$\ case 3
\end{gprogram}

6 Context Predicates

7 Context Predicates...

8 Multiple Context Predicates


Conclusion


9 Summary...

10 Summary

11 Homework

Example:
\begin{gprogram}
\redtxt{? dup 1} \\
\x (1,1) \\
\\
\redtxt{? dup ''Hello, me...
...
\\
\redtxt{? dup (dup 3.14)} \\
\x ((3.14,3.14), (3.14,3.14))
\end{gprogram}

12 Homework

Example:
\begin{gprogram}
\redtxt{? copy 5 ''five''} \\
\x [''five'',''five'',''five'',\...
...
\redtxt{? copy 5 (dup 5)} \\
\x [(5,5),(5,5),(5,5),(5,5),(5,5)]
\end{gprogram}

13 Homework

Example:
\begin{gprogram}
double x = 2*x\\
pow2 x = x\verb+^+2\\
totDub = total double\...
...\\
\redtxt{? totDub 5} \\
\x 30\\
\redtxt{? totPow 5}\\
\x 55
\end{gprogram}



Christian S. Collberg
2005-09-16