Thanks! (I hadn't even thought about how you might preserve polymorphism

within the loop).

Andrew

Seth J. Fogarty said:

>

> On Wed, 3 Nov 2004 21:54:11 -0300 (CLST), andrew cooke

> <andrew@...> wrote:

>>

>> Thanks for the reply.

>>

>> Just to get this straight, because i think I wasn't anything like clear

>> enough (I was not talking about function signatures, but about when

>> evaluation occurs), are you saying that for the first two examples:

>>

>> let f = exampleN 1 2 in

>> ...

>> let g = f 3

>

> 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

>

> I am not certain of the exactly optimizations used for each of these.

> Technically, yes, the first repeats the work and the second doesn't. I

> would not be surprised the least if the OCaml compiler optimises them

> to the same thing. It has done worse voodoo before.

>

>> 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?

>

> Baring acts of optimization, no, that would be the least efficient, as

> it has another closure, but it would preserve maximum polymorphism

> (i.e. if the type of x varied across the loop). Order-wise, same

> running time as example1.

>

> --

> 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.

>

>

>

> Archives up to September 30, 2004 are also downloadable at

> 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.

> Yahoo! Groups Links

>

>

>

>

>

>

>

>

--

` __ _ __ ___ ___| |_____ 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