caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Record field update using 'with' syntax
@ 2006-09-18 20:22 Denis Bueno
  2006-09-18 20:58 ` [Caml-list] " Martin Jambon
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Bueno @ 2006-09-18 20:22 UTC (permalink / raw)
  To: OCaml Mailing List

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
| #
`----


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-09-18 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-18 20:22 Record field update using 'with' syntax Denis Bueno
2006-09-18 20:58 ` [Caml-list] " Martin Jambon
2006-09-18 21:00   ` Denis Bueno
2006-09-18 21:16     ` Yoann Padioleau

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).