## 2736Re: 'ocaml_beginners'::[] Execution semantics

Expand Messages
• Nov 3, 2004
• 0 Attachment

Just to get this straight, because i think I wasn't anything like clear
evaluation occurs), are you saying that for the first two examples:

let f = exampleN 1 2 in
...
let g = f 3

most of the work (ie evaluating f1 and f2) *in both cases* is done before
the dots? So, for example, if "let g = ..." was in a loop, only the
minimum of work would be repeated.

And for example3, where I was clearly way too brief (sorry), I was
assuming that the answer to the above was "yes" and then considering

let f = fun (x -> example3 x 1 2) in
...
let g = f 3

Again, if g was evaluated in a loop, would that be as efficient as
examples 1 and 2?

I hope that's a little clearer.

Thanks,
Andrew

Seth J. Fogarty said:
>
> On Wed, 3 Nov 2004 16:03:20 -0300 (CLST), andrew cooke
> <andrew@...> wrote:
>>
>> Where can I find a clear description of how OCaml executes code. In
>> particular, I want to understand when functions with several values are
>> evaluated - is the evaluation progressive (during Currying) or is
>> evaluation delayed until all arguments are present.
>>
>> For example, are the following equivalent, always?
>>
>> let example1 a b x =
>> let a' = f1 a in
>> let b' = f2 b in
>> f3 a' b' x
>>
>> let example2 a b =
>> let a' = f1 a in
>> let b' = f2 b in
>> fun x -> f3 a' b' x
>
> These two are equivalent. I have a question, however, for the list.
> Why does example2, when so explicitly curried as such, have a '_a when
> curried?
>
>
> # let a = example2 1 2;;
> val a : '_a -> int * int * '_a = <fun>
>
> I know why example1 does this, I woul dhave thought example2 would not
> have.
>
>> let example3 x a b =
>> let a' = f1 a in
>> let b' = f2 b in
>> f3 a' b' x
>
> The order you pass the arguments in matters in OCaml, since the
> invoker has no names.
>
> example3 1 2 3
> binds 1 to x, 2 to a, and 3 to b.
> example1 1 2 3
> binds 1 to a, 2 to b, and 3 to x.
>
>> Thanks,
>> Andrew
>>
>> --
>> ` __ _ __ ___ ___| |_____ work web site:
>> http://www.ctio.noao.edu/~andrew
>> / _` / _/ _ \/ _ \ / / -_) personal web site:
>> http://www.acooke.org/andrew
>> \__,_\__\___/\___/_\_\___| list:
>> http://www.acooke.org/andrew/compute.html
>>
>>
>>
>> http://www.connettivo.net/cntprojects/ocaml_beginners/
>> The archives of the very official ocaml list (the seniors' one) can be
>> found at http://caml.inria.fr
>> Attachments are banned and you're asked to be polite, avoid flames etc.
>>
>>
>>
>>
>>
>>
>> ________________________________
>>
>> To visit your group on the web, go to:
>> http://groups.yahoo.com/group/ocaml_beginners/
>>
>> To unsubscribe from this group, send an email to:
>> ocaml_beginners-unsubscribe@yahoogroups.com
>>
>
>
> --
> Seth Fogarty sfogarty@[gmail.com|rice.edu|livejournal]
> Neep-neep at large AIM: Sorrath
> "I know there are people in this world who do not love their fellow
> human beings - and I hate people like that" --Tom Lehrer.
>
>
>
> http://www.connettivo.net/cntprojects/ocaml_beginners/
> The archives of the very official ocaml list (the seniors' one) can be
> found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
>
>
>
>
>
>
>
>

--
` __ _ __ ___ ___| |_____ work web site: http://www.ctio.noao.edu/~andrew
/ _` / _/ _ \/ _ \ / / -_) personal web site: http://www.acooke.org/andrew
\__,_\__\___/\___/_\_\___| list: http://www.acooke.org/andrew/compute.html
• Show all 26 messages in this topic