From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA14701 for caml-redistribution; Thu, 12 Aug 1999 16:42:39 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA00331 for ; Thu, 12 Aug 1999 14:02:42 +0200 (MET DST) Received: from buffalo.ens-lyon.fr (buffalo.ens-lyon.fr [140.77.1.8]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id MAA18669 for ; Thu, 12 Aug 1999 12:51:50 +0200 (MET DST) Received: from woodstock (woodstock [140.77.11.50]) by buffalo.ens-lyon.fr (8.9.1a/8.9.1) with ESMTP id MAA07839; Thu, 12 Aug 1999 12:51:11 +0200 (MET DST) Date: Thu, 12 Aug 1999 12:51:32 +0200 (MET DST) From: Nicolas Ollinger X-Sender: nollinge@woodstock To: John Skaller cc: caml-list@inria.fr Subject: Re: Constructor/reference bug? In-Reply-To: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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. --