English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Constructor/reference bug?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-08-12 (10:27)
From: John Skaller <skaller@m...>
Subject: Constructor/reference bug?
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
		phone: 61-2-96600850
		snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia