I have the following type
(* File: S.ml *)
module S = struct
type s =
{
a : int;
b : int;
}
end
I I have found that for creating records I can do as follows:
(* File: main.ml *)
open S
let s0 = S.{ a = 0; b = 0}
However this does not work for pattern matching:
(* this does not work *)
match s0 with
| S.{ a = 0 ; b = 0 } -> true
| _ -> false
These two alternatives work, but one with a warning and the other (depending on the type) is too verbose:
(* this produces a warning *)
match s0 with
| { a = 0 ; b = 0 } -> true
| _ -> false
(* this works *)
match s0 with
| { S.a = 0 ; S.b = 0 } -> true
| _ -> false
Is there any other way of writing pattern matches as compact as S.{ a = 0 ; b = 0 } ? (which is consistent to the construction of the same value)
I know that it's possible to do:
let open S in
match s0 with
| { a = 0 ; b = 0 } -> true
| _ -> false
but the main reason I don't do it is because I have more records like:
match s0,k0 with
| { S.a = 0 }, {K.a = 0 } -> true
Best regards,
Leonardo
--
Caml-list mailing list. Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs