Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] laziness
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-04 (11:49)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] laziness
Should be easy enough to test this:

let f a b c =
  if c then a else b

let r =
  f (print_endline "function a"; 'a')
    (print_endline "function b"; 'b')

Printf.printf "r = %c\n" r

When compiled with ocamlc and run, this prints:

function b
function a
r = a

When compiled with ocamlopt -inline 99 and run, this prints:

function a
function b
r = a

I examined the assembler output from ocamlopt, and it looks to me like
it's doing inlining and significant optimizations.

So it all works fine, I think.


Richard Jones.
Merjis Ltd. - improving website return on investment
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring: