caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Create Software <createsoftware@users.sourceforge.net>
To: caml-list@inria.fr
Subject: [Caml-list] Pattern-matching on Ocaml records
Date: Mon, 02 May 2011 14:32:36 +0200	[thread overview]
Message-ID: <4DBEA464.7090102@users.sourceforge.net> (raw)

Hi all,

I'm building an old Caml Light program with OCaml, and I've come across a reluctant piece of code. Here's a a mwe:

   type t = {mutable label: int};;
   let reset {label = lbl} = lbl <- 0;;

   let test = {label = -1};;
   reset test;;
   test;;

This compiles fine in Caml Light, yielding

   Type t defined.
   reset : t -> unit = <fun>
   test : t = {label = -1}
   - : unit = ()
   - : t = {label = 0}

On the other hand, Ocaml refuses this snippet, and prints the following message:

   Characters 26-34:
     let reset {label = lbl} = lbl <- 0;;
                               ^^^^^^^^
   Error: Unbound instance variable lbl

Was this construct deprecated? If so, why?

Thanks!
Clément.


PS: I also tried

   let reset' a =
     let lbl = a.label in
     lbl <- 0
   ;;

but "The identifier lbl is not mutable.", in both OCaml and Caml Light. Why so?

             reply	other threads:[~2011-05-02 12:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-02 12:32 Create Software [this message]
2011-05-02 12:44 ` Andreas Rossberg
2011-05-02 13:16   ` Create Software
2011-05-02 13:24     ` Andreas Rossberg
2011-05-02 13:33     ` Jacques Garrigue

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=4DBEA464.7090102@users.sourceforge.net \
    --to=createsoftware@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    /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).