caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Denis Bueno" <dbueno@gmail.com>
To: "OCaml Mailing List" <caml-list@inria.fr>
Subject: Record field update using 'with' syntax
Date: Mon, 18 Sep 2006 16:22:48 -0400	[thread overview]
Message-ID: <6dbd4d000609181322t787162anf370923383727626@mail.gmail.com> (raw)

Suppose a module M1 with the record

    type foo = {x : int; y : int; z : int};;

and a member of its type. In another module, a qualified field
matching like the following works:

    match instance with
      {M1.x = 5; y = 5; z = 100} -> (* something *)

Why doesn't the following work in a function?

    {M1.instance with x = 20}

It would seem easy to determine that x must name a field of a record inside M1.

Thanks for your help. (Example in OCaml 3.09.2 below.)

-Denis

Example:

,----
|         Objective Caml version 3.09.2
|
| # module M1 = struct
|       type foo = {x : int; y : int; z : int};;
|       let foo = {x = 10; y = 10; z = 10};;
|   end;;
| module M1 : sig type foo = { x : int; y : int; z : int; } val foo : foo end
| # match M1.foo with | {M1.x = 5; y = 5} -> ();;
| Characters 0-43:
| Warning P: this pattern-matching is not exhaustive.
| Here is an example of a value that is not matched:
| {x=0}
|   match M1.foo with | {M1.x = 5; y = 5} -> ();;
|   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Exception: Match_failure ("", 1, 0).
| # {M1.foo with x = 5};;
| Characters 0-19:
|   {M1.foo with x = 5};;
|   ^^^^^^^^^^^^^^^^^^^
| Unbound record field label x
| #
`----


             reply	other threads:[~2006-09-18 20:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-18 20:22 Denis Bueno [this message]
2006-09-18 20:58 ` [Caml-list] " Martin Jambon
2006-09-18 21:00   ` Denis Bueno
2006-09-18 21:16     ` Yoann Padioleau

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=6dbd4d000609181322t787162anf370923383727626@mail.gmail.com \
    --to=dbueno@gmail.com \
    --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).