caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Ollinger <nollinge@ens-lyon.fr>
To: John Skaller <skaller@maxtal.com.au>
Cc: caml-list@inria.fr
Subject: Re: Constructor/reference bug?
Date: Thu, 12 Aug 1999 12:51:32 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.GSO.4.10.9908121242090.15480-100000@woodstock> (raw)
In-Reply-To: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au>

On Wed, 11 Aug 1999, John Skaller wrote:

> I have some code like:

(snip)

> 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:
(!blob)::(f t)

Is translated into something like:
let arg2 = f t
and arg1 = !blob in
arg1::arg2

It calls f before computing !blob.

In hope this will help you,
N.
--





  reply	other threads:[~1999-08-12 14:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-11  8:05 John Skaller
1999-08-12 10:51 ` Nicolas Ollinger [this message]
1999-08-12 11:22 ` Jean-Christophe Filliatre
1999-08-12 11:25 ` Andreas Rossberg
1999-08-12 12:16 ` Markus Mottl
1999-08-12 12:05 Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.10.9908121242090.15480-100000@woodstock \
    --to=nollinge@ens-lyon.fr \
    --cc=caml-list@inria.fr \
    --cc=skaller@maxtal.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).