From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C3A117F736 for ; Wed, 16 Sep 2015 14:26:26 +0200 (CEST) IronPort-PHdr: 9a23:CjndOhWj0XE0D/UkqaWcQVXJCd7V8LGtZVwlr6E/grcLSJyIuqrYZhyFt8tkgFKBZ4jH8fUM07OQ6PC8HzZRqsre+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8GVOVQD2GX1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu3MRLkjVbFTEBghNmk04oWr6UiCHkOz4S44X2IQmwBEBEDh5R7nWJ65iDb7pKIp3S6WOcPxZb8xUDWmqaxsTUm7pj0AMmsf8WrQjsVrxIVZrR6o7zZ22caAZseSNvc4dKrHVdwfTGtFGM1WUnoSUcuHc4ITAr9Zbq5jpI7nqg5S/BY= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=n.oje.bar@gmail.com; spf=Pass smtp.mailfrom=n.oje.bar@gmail.com; spf=None smtp.helo=postmaster@mail-yk0-f170.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of n.oje.bar@gmail.com) identity=pra; client-ip=209.85.160.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="n.oje.bar@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of n.oje.bar@gmail.com designates 209.85.160.170 as permitted sender) identity=mailfrom; client-ip=209.85.160.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="n.oje.bar@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yk0-f170.google.com) identity=helo; client-ip=209.85.160.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="postmaster@mail-yk0-f170.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BNAwCyXvlVlKqgVdFdg0I1Wg8GqmyBTpJuhXkCgTkHPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBAwESEQQZARsSCwEDDAYDAgQHGh0CAiEBAREBBQEKEgYTEhCHdgEDCggNl2ePRoEwPjGLRoFsgnmKJAoZJwMKVoQMAQEBAQEBBAEBAQEBARYBBQ6GZoR8glCCOQQHgmmBQwWFfAyPVoUQgm2DGYFtghORP4VyEiOBFxEngi+BfzwziioBAQE X-IPAS-Result: A0BNAwCyXvlVlKqgVdFdg0I1Wg8GqmyBTpJuhXkCgTkHPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBAwESEQQZARsSCwEDDAYDAgQHGh0CAiEBAREBBQEKEgYTEhCHdgEDCggNl2ePRoEwPjGLRoFsgnmKJAoZJwMKVoQMAQEBAQEBBAEBAQEBARYBBQ6GZoR8glCCOQQHgmmBQwWFfAyPVoUQgm2DGYFtghORP4VyEiOBFxEngi+BfzwziioBAQE X-IronPort-AV: E=Sophos;i="5.17,539,1437429600"; d="scan'208";a="177873471" Received: from mail-yk0-f170.google.com ([209.85.160.170]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 Sep 2015 14:26:26 +0200 Received: by ykdt18 with SMTP id t18so196347408ykd.3 for ; Wed, 16 Sep 2015 05:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=S8R2NbIfedhW3Uhxx3QfmkLC5bsf8Ptma7hHu6I3ylk=; b=FImSmvScfpTEy3sFYRU31kp1f6Cq45647rg/sGvxS2BXBZGw1I8LJ23ttauuYhcjAy 5diegH0a+tmaIwooiiW8ly6YnSx8H/8Z0sW9IDDM872Z1gZr/L8Rna8B+ZXqftENBJJK x9Z+e517/Yh/I+E/C7MqnZbCjU5UMwI9NMP4jeoMdPQijlW5PE3inIbScsCv//qD18Mi DRp8fv3bQt6zFLyGmjFC5+R0VGaQWPHcgO1Iihk2oxhWEdO37uxI7bmQV2PwTHVfdKXp 6ejkGmHFsOyjt8u4yCSxxJQRmaELebWTR2XdDry+COupv9dwK7vfcLZXost3t7vNZs3V rZCA== MIME-Version: 1.0 X-Received: by 10.170.110.210 with SMTP id c201mr28347375ykb.1.1442406385161; Wed, 16 Sep 2015 05:26:25 -0700 (PDT) Received: by 10.37.202.7 with HTTP; Wed, 16 Sep 2015 05:26:25 -0700 (PDT) In-Reply-To: <55F95E5E.6000209@gmail.com> References: <55F95E5E.6000209@gmail.com> Date: Wed, 16 Sep 2015 14:26:25 +0200 Message-ID: From: Nicolas Ojeda Bar To: Leonardo Laguna Ruiz Cc: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=001a1137948e359e8b051fdc680a Subject: Re: [Caml-list] Pattern matching of records --001a1137948e359e8b051fdc680a Content-Type: text/plain; charset=UTF-8 Hi Leonardo, You only need to fully qualify _one_ label in order to disambiguate the record type, for example: match s0 with | {S.a = 0; b = 0} -> true | _ -> false Cheers, Nicolas On Wed, Sep 16, 2015 at 2:19 PM, Leonardo Laguna Ruiz wrote: > > 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 > --001a1137948e359e8b051fdc680a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Leonardo,

You only need to fully qua= lify _one_ label in order to disambiguate the record type, for example:

=C2=A0 match s0 with
=C2=A0 | {S.a =3D 0; b= =3D 0} -> true
=C2=A0 | _ -> false

Cheers,
Nicolas


On Wed, Sep 16, 2015 at 2:19 PM, Leona= rdo Laguna Ruiz <modlfo@gmail.com> wrote:

I have the following type

(* File: S.ml *)
module S =3D struct
=C2=A0 =C2=A0type s =3D
=C2=A0 =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0a : int;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0b : int;
=C2=A0 =C2=A0 =C2=A0 }
end


I I have found that for creating records I can do as follows:

(* File: ma= in.ml *)
open S
let s0 =3D S.{ a =3D 0; b =3D 0}


However this does not work for pattern matching:

(* this does not work *)
match s0 with
| S.{ a =3D 0 ; b =3D 0 } -> true
| _ -> false


These two alternatives work, but one with a warning and the other (dependin= g on the type) is too verbose:

(* this produces a warning *)
match s0 with
| { a =3D 0 ; b =3D 0 } -> true
| _ -> false

(* this works *)
match s0 with
| { S.a =3D 0 ; S.b =3D 0 } -> true
| _ -> false


Is there any other way of writing pattern matches as compact as S.{ a =3D 0= ; b =3D 0 } ? (which is consistent to the construction of the same value)<= br>
I know that it's possible to do:

let open S in
match s0 with
| { a =3D 0 ; b =3D 0 } -> true
| _ -> false

but the main reason I don't do it is because I have more records like:<= br>
match s0,k0 with
| { S.a =3D 0 }, {K.a =3D 0 } -> true



Best regards,

Leonardo



--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocam= l_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001a1137948e359e8b051fdc680a--