From: cheno@micronet.fr (Laurent CHENO)
To: caml-list@margaux.inria.fr
Subject: Re: curried fns
Date: Mon, 20 Nov 1995 20:51:56 +0200 [thread overview]
Message-ID: <v01520c01acd67e5be62c@[194.51.75.132]> (raw)
Jocelyn Serot wrote :
>>Hello,
>>
>>Could someone please explain the difference(s) between:
>>
>> let f x = function y -> y + x;;
>>
>>and
>>
>> let f x y = y + x;;
>>
>>Both have the same type (int -> int -> int) but they seem to behave
>>distinctly wrt evaluation strategy.
>>
>>For instance, if i use the 1st form and write:
>>
>> let h x = let z = fact x in fun y -> y + z;;
>> map (h 30) [1;2;3];; (* note 1 *)
>>
>>fact 30 gets evaluated only once (partial evaluation), while
>>the use of the 2nd form for the h function:
>>
>> let h x y = let z = fact x in y + z;;
>> map (h 30) [1;2;3];;
>>
>>causes fact 30 to be evaluated _for each_ element of the list.
>>
>>Is this normal or do i misunderstand sth about curryfied fns ?..
>>
>>Thanks for any help
1. excuse my poor english, thank's
2. I think this can help (I hope so !)
For my example :
#let fact x = print_int x ; print_newline() ; x ;;
fact : int -> int = <fun>
first version
#let h1 x =
let z = fact x
in
function y -> y + z ;;
h1 : int -> int -> int = <fun>
NB : the result of h1 30 is a function, which has been evaluated in a
environment where
z yields for the result of fact 30
So, we can see the result of print_int in *this* call !
#let a1 = h1 30 ;;
30
a1 : int -> int = <fun>
Now, a1 is all defined : no more print ... the function a1 don't print anything
#map a1 [1 ; 2 ; 3] ;;
- : int list = [31; 32; 33]
second version
#let h2 x y =
let z = fact x
in
y + z ;;
h2 : int -> int -> int = <fun>
there is no call for fact : you have specialized the first (and not last)
argument of h2
#let a2 = h2 30 ;;
a2 : int -> int = <fun>
now the evaluation is complete, and there is calls for print_int
#map a2 [1 ; 2 ; 3] ;;
30
30
30
- : int list = [31; 32; 33]
#
Laurent Chéno
-------------------------------------------------------------------
Laurent CHENO teaching at / enseignant au
Lycée Louis-le-Grand - 123 rue Saint-Jacques
75231 PARIS CEDEX 05 - FRANCE
personal phone (33) 1 48 05 16 04 - fax (33) 1 48 07 80 18
-------------------------------------------------------------------
next reply other threads:[~1995-11-21 10:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-11-20 18:51 Laurent CHENO [this message]
-- strict thread matches above, loose matches on Subject: below --
1995-11-21 5:17 Tarizzo Martial
1995-11-20 20:32 Fauque UPS
1995-11-20 15:54 Jocelyn Serot
1995-11-20 18:06 ` John Harrison
1995-11-21 10:48 ` Pierre Weis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='v01520c01acd67e5be62c@[194.51.75.132]' \
--to=cheno@micronet.fr \
--cc=caml-list@margaux.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox