Commit 2f1e8c52 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2006-05-29 14:58:18 by ngesbert] -- added a few missing parentheses in type examples (operator

precedences still aren't documented but the examples are now correct
wrt current implementation, and still will if precedences are changed)
-- slightly changed the description of the general form of a function
declaration in the quick reference card: the number of types need not
be the same as the nnumber of patterns, which the previous description
seemed to imply.

Original author: ngesbert
Date: 2006-05-29 14:58:18+00:00
parent 60f9f5e4
......@@ -369,14 +369,14 @@ type t = [ <a>(t @ t) ? ] (* [s?] where s=<a>[ s? s? ] *)
type x = [ Int* ]
type y = x @ [ Char* ] (* [ Int* Char* ] *)
type t = [Int] @ t | [] (* [ Int* ] *)
type t = ([Int] @ t) | [] (* [ Int* ] *)
]]></sample>
<p>
however when used in recursive definitions <code>@</code> but must be right linear so for instance the following definition are not allowed:
</p>
<sample><![CDATA[
type t = t @ [Int] | [] (* ERROR: Ill-formed concatenation loop *)
type t = (t @ [Int]) | [] (* ERROR: Ill-formed concatenation loop *)
type t = t @ t (* ERROR: Ill-formed concatenation loop *)
]]></sample>
......@@ -559,7 +559,7 @@ where <code>%%t%%</code> and <code>%%s%%</code> are types.
Intuitively, this type corresponds to functions that accept
(at least) any argument of type <code>%%t%%</code>, and for
such an argument, returns a value of type <code>%%s%%</code>.
For instance, the type <code>(Int,Int) -> Int &amp; (Char,Char) -> Char</code>
For instance, the type <code>((Int,Int) -> Int) &amp; ((Char,Char) -> Char)</code>
denotes functions that maps any pair of integer to an integer,
and any pair of characters to a character.
</p>
......@@ -569,7 +569,7 @@ The explanation above gives the intuition behind the interpretation
of functional types. It is sufficient to understand which
subtyping relations and equivalences hold between (boolean
combination) of functional types. For instance,
<code>Int -> Int &amp; Char -> Char</code> is a subtype
<code>(Int -> Int) &amp; (Char -> Char)</code> is a subtype
of <code>(Int|Char) -> (Int|Char)</code> because
with the intuition above, a function of the first type,
when given a value of type <code>Int|Char</code> returns
......@@ -581,8 +581,8 @@ a value of type <code>Int</code> or of type <code>Char</code>
Formally, the type <code>%%t%% -> %%s%%</code> denotes
CDuce abstractions
<code>fun (%%t1%% -> %%s1%%; %%...%%; %%tn%% -> %%sn%%)...</code>
such that <code>%%t1%% -> %%s1%% &amp; %%...%% &amp; %%tn%% ->
%%sn%%</code> is a subtype of <code>%%t%% -> %%s%%</code>.
such that <code>(%%t1%% -> %%s1%%) &amp; %%...%% &amp; (%%tn%% ->
%%sn%%)</code> is a subtype of <code>%%t%% -> %%s%%</code>.
</p>
<p>
......
......@@ -204,7 +204,7 @@ field <code>l</code> is not present)</li>
<li>Expressions:
<ul>
<li>General form: <code>fun f (t1->s1;...;tn->sn)
p1 -> e1 | ... | pn -> en</code> (<code>f</code> is optional) </li>
p1 -> e1 | ... | pm -> em</code> (<code>f</code> is optional) </li>
<li>Simple function: <code>fun f (p : t) : s = e</code>,
equivalent to <code>fun f (t -> s) p -> e</code> </li>
<li>Multiple arguments: <code>fun f (p1 : t1, p2 : t2,...) : s =
......
......@@ -40,7 +40,7 @@ let %%f%% (%%t1%%->%%s1%%;...;%%tn%%->%%sn%%) %%p1%% -> %%e1%% | ... | %%pm%% ->
<p>
Such a function accepts arguments of type
(<code>%%t1%%|...|%%tn%%</code>); it has all the types <code>%%ti%%->%%si%%</code>, and,
thus, it also has their intersection <code>%%t1%%->%%s1%%&amp;...&amp;%%tn%%->%%sn%%</code>
thus, it also has their intersection <code>(%%t1%%->%%s1)%%&amp;...&amp;(%%tn%%->%%sn%%)</code>
</p>
<p>
......@@ -167,7 +167,7 @@ the type checker deduces that the expressions <code>&lt;sons>s</code> and
returns for the <code>split</code> function the type <code>(MPerson -> Man) &amp; (FPerson
-> Woman)</code>. Note that the use of overloading here is critical: although
<code>split</code> has <i>also</i> type <code>Person ->(Man | Woman)</code> (since <code>split</code> is of type
<code>MPerson->Man &amp; FPerson->Woman</code>, which is a subtype), had we
<code>(MPerson->Man) &amp; (FPerson->Woman)</code>, which is a subtype), had we
declared <code>split</code> of that type, the function would not have type-checked: in
the recursive calls we would have been able to deduce for <code>s</code> and for
<code>d</code> the type <code>[ (Man | Woman)* ]</code>, which is not enough to type-check the
......
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