Commit f55f9f27 authored by Mickael Laurent's avatar Mickael Laurent
Browse files

add record example

parent 1ebe614a
......@@ -106,19 +106,19 @@ let test_3 = f nil nil
\\\hline
8 &
\begin{lstlisting}
atom nil
type Document = { nodeType=9 ..}
and Element = { nodeType=1, childNodes=NodeList ..}
and Text = { nodeType=3,
isElementContentWhiteSpace=Bool ..}
isElementContentWhiteSpace=Bool ..}
and Node = Document | Element | Text
and NodeList = Nil | (Node, NodeList)
let is_empty_node = fun (x : Node) ->
if x.nodeType is 9 then false
else if x.nodeType is 3 then
else if x is { nodeType=3 ..} then
x.isElementContentWhiteSpace
else
if x.childNodes is Nil then true else false
else if x.childNodes is Nil then true else false
\end{lstlisting} &\vspace{12mm}
$(\Keyw{Document}\to\False)~\land$\newline
$(\orecord{ \texttt{nodeType}\,{=}\,1, \texttt{childNodes}\,{=}\,\Keyw{Nil} }\to\True) ~\land$\newline
......@@ -136,7 +136,6 @@ let xor_ = fun (x : Any) -> fun (y : Any) ->
$\True\to((\True\to\False)\land(\lnot\True\to\True))~\land$\newline
$(\lnot\True\to((\True\to\True) \land (\lnot\True\to\False))$
\\\hline
10 & \begin{lstlisting}
(* f, g have type: (Int->Int) & (Any->Bool) *)
......@@ -146,6 +145,33 @@ let example10 = fun (x : Any) ->
$(\Int\to\textsf{Empty})\land(\neg\Int\to{}2)$\newline
\texttt{Warning: line 4, 39-40: unreachable expression}
\\\hline
11 & \begin{lstlisting}
atom nil
type Object = Nil | { prototype = Object ..}
type ObjectWithPropertyL = { l = Any ..}
| { prototype = ObjectWithPropertyL ..}
let has_property_l = fun (o:Object) ->
if o is ObjectWithPropertyL then true else false
let has_own_property_l = fun (o:Object) ->
if o is { l=Any ..} then true else false
let get_property_l = fun (self:Object->Any) o ->
if has_own_property_l o is True then o.l
else if o is Nil then nil
else self (o.prototype)
\end{lstlisting} &\vfill\medskip\smallskip
$(\Keyw{ObjectWithPropertyL}\to\True)$ $\land$
$(\Keyw{X1}\to\False) \texttt{ where}$\newline
$\Keyw{X1}\,=\,(\Keyw{Nil}\,|\,\orecord{\texttt{l}\,{=}\,?\Keyw{Empty},\, \texttt{prototype}\,{=}\,\Keyw{X1}})$\newline
~\newline
$(\orecord{\Keyw{l}\,=\,\Keyw{Any}, \texttt{prototype}\,=\,\Keyw{Object}}\to\True)$ $\land$\newline
$((\Keyw{Nil}\,|\,\orecord{\texttt{l}\,=\,?\Keyw{Empty},\, \texttt{prototype}\,=\,\Keyw{Object}})\to\False)$\newline
\newline
~\newline
$\Keyw{Object}\to\Keyw{Any}$
\\\hline
\end{tabular}
}
\caption{Types inferred by the implementation}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment