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 MAA03535 for caml-redistribution; Thu, 12 Aug 1999 12:27:51 +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 QAA04383 for ; Wed, 11 Aug 1999 16:51:56 +0200 (MET DST) Received: from iggy.triode.net.au (iggy.triode.net.au [203.63.235.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id QAA29356 for ; Wed, 11 Aug 1999 16:51:53 +0200 (MET DST) Received: from egret (pm1-16.triode.net.au [203.63.235.32]) by iggy.triode.net.au (8.9.3/8.8.8) with SMTP id AAA31232 for ; Thu, 12 Aug 1999 00:46:23 +1000 Message-Id: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au> X-Sender: skaller@mail.triode.net.au X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) Date: Wed, 11 Aug 1999 18:05:30 +1000 To: caml-list@inria.fr From: John Skaller Subject: Constructor/reference bug? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: weis I have some code like: let g x = let lineno = ref (1,"") in let rec f x' = match x' with | NEWLINE p :: t -> lineno := p; f t | COLON :: t -> CTRL !lineno :: f t | h :: t -> h :: f t | [] -> [] in f x;; The code doesn't work as I expected: every CTRL value refers to the same lineno, the last one. If I change the COLON line to read: | COLON :: t -> let x = !lineno in CTRL x :: f t the code works as expected -- the CTRL refers to the value of lineno at the time the last NEWLINE was processed. What's happening? Are coproduct constructors lazy? [I tested some simpler samples by hand and my tests worked as expected, so I'm confused] ------------------------------------------------------- John Skaller email: skaller@maxtal.com.au http://www.maxtal.com.au/~skaller phone: 61-2-96600850 snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia