Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jean-Christophe Filliatre <filliatr@l...>
Subject: Re: Constructor/reference bug?

> | COLON :: t     -> CTRL !lineno :: f t
>
> 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:

That is only because the second argument is evaluated before the first
one in a cons (::). Indeed, you can try 

======================================================================
# print_int 1 :: print_int 2 :: [];;
======================================================================

and you will get 

======================================================================
21- : unit list = [(); ()]
======================================================================

It explains  your problem. As you  can read it in  the ocaml reference
manual,  the  order  of  evaluation  of tuples  elements  in  the  not
specified :

======================================================================
Products

The expression expr1 ,..., exprn evaluates to the n-tuple of the values of expressions expr1 to exprn. The
evaluation order for the subexpressions is not specified.

Variants

The expression ncconstr expr evaluates to the variant value whose constructor is ncconstr, and whose argument
is the value of expr.
======================================================================

so your second code with a "let in" should be used. 

> | COLON :: t -> let x = !lineno in CTRL x :: f t

Best regards,
-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr