\documentclass{beamer}

\usepackage{xcolor}
\usepackage{listings}
\usepackage{clean}
\usepackage{spl}

\title[cc1516]{SPLC}
\subtitle{\texttt{<splc>~::= <spl> <parser> `,' <lexer> `and' <compiler>}}
\author[P. Jager, M. Lubbers]{Pim Jager\inst{1}\and Mart Lubbers\inst{1}}
\institute[Radboud University]{%
	\inst{1}%
	Computer Science: Software Science\\
	Radboud University
}
\subject{SPL Compiler}
\date{\today}

\lstset{%
	basicstyle=\ttfamily\footnotesize,
	breaklines
}

\usetheme{Warsaw}
\usecolortheme{beaver}

\begin{document}
\frame{\titlepage}

\begin{frame}[fragile]
	\frametitle{Higher order functions implemented using function pointers}

	\begin{SPLCode}
map(f, xs) :: (a -> b) -> [a] -> [b] {
	if( isEmpty(xs) ) { return []; }
	else { return f(xs.hd) : map(f, xs.tl); }
}
id(x) { return x; }

main() {
	map(id, 1:2:3:[]);
}
	\end{SPLCode}
	\pause
	\begin{itemize}
		\item Function arguments are passed by name.
		\item During compilation these are replaced by unique function ID's
		\item During runtime the corresponding function label is retrieved using
			a dictionary like approach. 
	\end{itemize}

\end{frame}

\begin{frame}[fragile]
	\frametitle{Functions application can be curried}

	\begin{SPLCode}
plus(x,y) :: Int -> Int -> Int {
	return x + y;
}

main() {
	map(plus(1), 1:2:3:[]);
}
	\end{SPLCode}
	\pause
	\begin{columns}[T]
		\begin{column}[T]{0.5\textwidth}
			\begin{enumerate}
				\item Function ID is placed on the heap
				\item Number of passed arguments is placed on the heap
				\item Arguments are pushed on the heap
			\end{enumerate}
		\end{column}
		\pause
		\begin{column}[T]{0.5\textwidth}
			\begin{block}{Heap contents}
			\begin{tabular}{c | l | r}
				address & Content & \\  \hline
				n 	& 8 & (1)\\  
				n+1 & 1 & (2)\\  
				n+2 & 4 & (3)
			\end{tabular}
			\end{block}
		\end{column}
	\end{columns}

\end{frame}

\end{document}
