caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: skaller@maxtal.com.au (John Skaller)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: Constructor/reference bug?
Date: Thu, 12 Aug 1999 13:16:03 +0100 (MET DST)	[thread overview]
Message-ID: <199908121116.NAA02423@miss.wu-wien.ac.at> (raw)
In-Reply-To: <3.0.6.32.19990811180530.00985e40@mail.triode.net.au> from "John Skaller" at Aug 11, 99 06:05:30 pm

> 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?

No, but OCaml evaluates all kind of expressions right-to-left which is
probably not very intuitive for people who are used to read from left
to right...

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




  parent reply	other threads:[~1999-08-12 14:39 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
1999-08-12 11:22 ` Jean-Christophe Filliatre
1999-08-12 11:25 ` Andreas Rossberg
1999-08-12 12:16 ` Markus Mottl [this message]
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=199908121116.NAA02423@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --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).