Commit e02398cb authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-05-25 09:57:31 by afrisch] Doc currified funs

Original author: afrisch
Date: 2004-05-25 09:57:31+00:00
parent 4114e904
......@@ -21,6 +21,11 @@ let f2 (x : Int, y : Int) : Int = x + y
;;
f2 (10,20)
(* Currified form *)
let add (x : Int) (y : Int) : Int = x + y
;;
add 10 20
(* You may directly deconstruct the arguments: *)
type A = <a href=String>String
let f3 (<a href=url>txt : A) : String = url @ \"=>\" @ txt
......
......@@ -8,6 +8,11 @@ let f2 (x : Int, y : Int) : Int = x + y
;;
f2 (10,20)
(* Currified form *)
let add (x : Int) (y : Int) : Int = x + y
;;
add 10 20
(* You may directly deconstruct the arguments: *)
type A = <a href=String>String
let f3 (<a href=url>txt : A) : String = url @ "=>" @ txt
......
......@@ -142,6 +142,26 @@ equivalent to:
<sample><![CDATA[
fun %%f%% ((%%t1%%,%%...%%,%%tn%%) -> %%s%%) (%%p1%%,%%...%%,%%pn%%) -> %%e%%
]]></sample>
<p>
It is also possible to define currified functions with this syntax:
</p>
<sample><![CDATA[
fun %%f%% (%%p1%% : %%t1%%, %%...%%, %%pn : tn%%) (%%q1%% : %%s1%%, %%...%%, %%qm : sm%%) %%...%% : %%s%% = %%e%%
]]></sample>
<p>
which is strictly
equivalent to:
</p>
<sample><![CDATA[
fun %%f%% ((%%t1%%,%%...%%,%%tn%%) -> (%%s1%%,%%...%%,%%sm%%) -> %%...%% -> %%s%%)
(%%p1%%,%%...%%,%%pn%%) ->
fun ((%%s1%%,%%...%%,%%sm%%) -> %%...%% -> %%s%%)
(%%q1%%,%%...%%,%%qm%%) ->
%%...%%
%%e%%
]]></sample>
<p>
The standard notation for local binding a function is:
</p>
......
......@@ -169,7 +169,10 @@ field <code>l</code> is not present)</li>
equivalent to <code>fun f (t -> s) p -> e</code> </li>
<li>Multiple arguments: <code>fun f (p1 : t1, p2 : t2,...) : s =
e</code>, equivalent to <code>fun f ((p1,p2,...):(t1,t2,...)) : s
= e</code> (note the blank spaces around colons to avoid ambiguity with namespaces) </li>
= e</code> (note the blank spaces around colons to avoid ambiguity
with namespaces) </li>
<li>Currified function: <code>fun f (p1 : t1) (p2 : t2) ... : s =
e</code> (can be combined with the multiple arguments syntax).</li>
</ul>
</li>
<li>Types: <code>t -> s</code> </li>
......
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