Browse thread
Record field update using 'with' syntax
- Denis Bueno
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-09-18 (20:22) |
From: | Denis Bueno <dbueno@g...> |
Subject: | Record field update using 'with' syntax |
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 | # `----