Pair example
This commit is contained in:
parent
3a9f2d3e16
commit
b577881d92
@ -584,14 +584,23 @@ compare(p); // Error
|
|||||||
|
|
||||||
Our type inference algorithm is not able to solve this example.
|
Our type inference algorithm is not able to solve this example.
|
||||||
When we convert this to \TamedFJ{} and generate constraints we end up with:
|
When we convert this to \TamedFJ{} and generate constraints we end up with:
|
||||||
%TODO: Finish this example! does it work?
|
|
||||||
\begin{lstlisting}[style=tamedfj]
|
\begin{lstlisting}[style=tamedfj]
|
||||||
let x = l in let m = make(x) in compare(m)
|
let m = let x = l in make(x) in compare(m)
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
\begin{constraints}
|
\begin{constraintset}$
|
||||||
|
\wctype{\rwildcard{X}}{List}{\rwildcard{X}} \lessdot \ntv{x},
|
||||||
|
\ntv{x} \lessdotCC \exptype{List}{\wtv{a}}
|
||||||
|
\exptype{Pair}{\wtv{a}, \wtv{a}} \lessdot \ntv{m}, %% TODO: Mark this constraint
|
||||||
|
\ntv{m} \lessdotCC \exptype{Pair}{\wtv{b}, \wtv{b}}
|
||||||
|
$\end{constraintset}
|
||||||
|
|
||||||
\end{constraints}
|
$\ntv{x}$ will get the type $\wctype{\rwildcard{X}}{List}{\rwildcard{X}}$ and
|
||||||
|
from the constraint
|
||||||
|
$\wctype{\rwildcard{X}}{List}{\rwildcard{X}} \lessdot \exptype{List}{\wtv{a}}$
|
||||||
|
\unify{} deducts $\wtv{a} \doteq \rwildcard{X}$ leading to
|
||||||
|
$\exptype{Pair}{\rwildcard{X}, \rwildcard{X}} \lessdot \ntv{m}$.
|
||||||
|
|
||||||
|
Finding a supertype to $\exptype{Pair}{\rwildcard{X}, \rwildcard{X}}$ is the crucial part.
|
||||||
%TODO
|
%TODO
|
||||||
|
|
||||||
\begin{lstlisting}[style=letfj]
|
\begin{lstlisting}[style=letfj]
|
||||||
|
Loading…
Reference in New Issue
Block a user