Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: [Caml-list] optimizing trivial functions

0 views
Skip to first unread message

Sean McLaughlin

unread,
Nov 27, 2006, 4:39:32 AM11/27/06
to Sean McLaughlin

To answer my own question, of course it can't do that, because the
arguments could have side effects. I wonder if Haskell would do
this...

Sean

f (print_int 5) ...

On Nov 21, 2006, at 6:20 PM, Sean McLaughlin wrote:

> Hello,
>
> Will the Ocaml compiler optimize the following code to let y = ()?
> I'm designing a program that will depend heavily on whether this code
> is optimized in this way.
>
> let f x1 x2 ... x100 = ()
> let y = f x1 ... x100
>
> Thanks,
>
> Sean
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Dmitry Bely

unread,
Nov 27, 2006, 7:05:00 AM11/27/06
to caml...@inria.fr
On 11/26/06, Sean McLaughlin <sea...@cmu.edu> wrote:

> > Will the Ocaml compiler optimize the following code to let y = ()?
> > I'm designing a program that will depend heavily on whether this code
> > is optimized in this way.
> >
> > let f x1 x2 ... x100 = ()
> > let y = f x1 ... x100

Yes, ocamlopt can do that.

> To answer my own question, of course it can't do that, because the
> arguments could have side effects.
>

> f (print_int 5) ...

So what? The arguments will be evaluated but the function call will be
optimized away.

I guess you are trying to implement some debugging that can be
switched off in the release version? If so, the following might be
interesting for you:

http://caml.inria.fr/pub/ml-archives/caml-list/2003/09/f2bf1cc8545d5e073638bd70d02b5056.en.html

- Dmitry Bely

0 new messages