Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Mark Cohen
/
thesis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5398f31b
authored
Jun 05, 2019
by
Mark Cohen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
presentation: content done
parent
e6511be5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
10 deletions
presentation/main.tex
presentation/main.tex
View file @
5398f31b
...
...
@@ -1035,6 +1035,83 @@ instance Iterable string where
\end{frame}
\begin{frame}
[fragile]
{
Associated types: formalisms
}
\begin{onlyenv}
\begin{lstlisting}
[mathescape=true]
class Collectible
$
\alpha
$
where
type item
val empty:
$
\alpha
$
val insert:
$
\alpha
$
$
\arrow
$
item
$
\arrow
$
$
\alpha
$
\end{lstlisting}
\end{onlyenv}
\note
[item]
{
Here we have the definition of the
\tt
{
Collectible
}
type class using the associated item type.
}
\begin{onlyenv}
<2->
\begin{itemize}
\item
{
$
\tt
{
over empty
}
::
\forall
\tt
{
item
}
.
\forall
\alpha
.
\;
\alpha
\tt
{
in
}
\ldots
$
}
\item
{
$
\tt
{
over insert
}
::
\forall
\tt
{
item
}
.
\forall
\alpha
.
\;
\alpha
\arrow
\tt
{
item
}
\arrow
\alpha
=
\ldots
\tt
{
in
}
\ldots
$
}
\end{itemize}
\end{onlyenv}
\note
[item]
{
Since we are not allowing higher-kinded associated types, we just translate away the overloaded
type declaration into an extra generalization.
}
\begin{onlyenv}
<3->
\begin{lstlisting}
[mathescape=true]
instance Collectible string where
type item = char
val empty = ""
val next = fn xs =>
if xs = ""
then None
else Some (hd xs, tl xs)
\end{lstlisting}
\end{onlyenv}
\note
[item]
{
Here we have a complete instance of
\tt
{
Collectible
}
for lists. Notice how here we specify the
item type in terms of the instance type.
}
\begin{onlyenv}
<4->
\begin{itemize}
\item
{
$
\tt
{
inst empty
}
::
\tt
{
string
}
=
""
\tt
{
in
}
\ldots
$
}
\item
{
$
\tt
{
inst insert
}
::
\tt
{
string
}
\arrow
\tt
{
char
}
\arrow
\tt
{
string
}
=
\lambda
\tt
{
s
}
.
\lambda
\tt
{
c
}
\ldots
\tt
{
in
}
\ldots
$
}
\end{itemize}
\end{onlyenv}
\note
[item]
{
Now, to translate this, all we have to do is substitute in
$
\alpha
$
everywhere we saw
\tt
{
item
}
in the type of the overloaded operator above.
}
\note
[item]
{
Then, when we go to translate from the intermediate language here to the internal language, we
just check that the annotated type here unifies with the inferred type of the lambda body.
}
\end{frame}
\begin{frame}
[fragile]
{
Iteration: formalisms
}
Recall our desired designs:
\begin{lstlisting}
[mathescape=true]
...
...
@@ -1162,20 +1239,46 @@ pass
\begin{frame}
[fragile]
{
Iteration: big payoff!
}
\begin{lstlisting}
[mathescape=true]
val pass = fn
_
=> None
val collect = fn x => Some x
val for = fn var collection
$
\iota
$
expr =>
case (next collection)
of None =>
$
\iota
$
| Some (item, rest) =>
case (expr item)
of Some item' => for var rest (insert
$
\iota
$
item') expr
| None => for var rest
$
\iota
$
expr
let
val pass = None
val collect = fn x => Some x
val for = fn collection
$
\iota
$
expr =>
case (next collection)
of None =>
$
\iota
$
| Some (item, rest) =>
case (expr item)
of Some item' => for rest (insert
$
\iota
$
item') expr
| None => for rest
$
\iota
$
expr
in
for <var> <collection> empty (fn <var> => <expr>)
end
\end{lstlisting}
\end{frame}
\begin{frame}
[fragile]
{
Iteration: big payoff!
}
\begin{lstlisting}
[mathescape=true]
for id in users
$
\arrow
$
string list
if registered? id
then collect id
else pass
\end{lstlisting}
\begin{onlyenv}
<2->
\begin{lstlisting}
[mathescape=true]
<expr>
$
\mapsto
$
fn <var> => <expr>
let
val pass = None
val collect = fn x => Some x
val for = fn collection
$
\iota
$
expr =>
case (next collection)
of None =>
$
\iota
$
| Some (item, rest) =>
case (expr item)
of Some item' => for rest (insert
$
\iota
$
item') expr
| None => for rest
$
\iota
$
expr
in
for users [] (fn id => if registered? id then collect id else pass)
end
\end{lstlisting}
\end{onlyenv}
\end{frame}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment