Date: Thu, 12 Aug 1999 12:51:32 +0200 (MET DST)
From: Nicolas Ollinger <firstname.lastname@example.org>
To: John Skaller <email@example.com>
Subject: Re: Constructor/reference bug?
On Wed, 11 Aug 1999, John Skaller wrote:
> I have some code like:
> What's happening? Are coproduct constructors lazy?
> [I tested some simpler samples by hand and my tests
> worked as expected, so I'm confused]
here is a simpler sample :
let blob = ref 0 in
let rec f = function
| true::t -> incr blob; f t
| false::t -> (!blob)::(f t)
|  -> 
in f [true;false;false;false;true;true;false];;
the result is : [3; 3; 3; 3].
But this is not a bug... this is normal!
And of course if you write let tmp = !blob in tmp::(f t) the
result will be [1; 1; 1; 3].
You don't see why it is so because there is a mix of infix and prefix
operators there. But remember that the order of arguments evaluation is
not specified in Caml. And precisely, OCaml do it from right to left.
Then, the text:
Is translated into something like:
let arg2 = f t
and arg1 = !blob in
It calls f before computing !blob.
In hope this will help you,
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:24 MET