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 40FAE7F736 for ; Wed, 16 Sep 2015 14:28:14 +0200 (CEST) IronPort-PHdr: 9a23:5z0eBROQZyDfFz37gosl6mtUPXoX/o7sNwtQ0KIMzox0KPj6rarrMEGX3/hxlliBBdydsKIYzbCH+P28EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35jxjbH5psGbSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf9d32JiKAHbtR/94sCt4MwrqHwI6Lpyv/JHBK7zeqB9Sb1DEBwnNXo07Yvlr0rtVwyKs18RVWMfiBZPSyzM4wz8V9/Lryro/r543yWeM8reQrU9WDDk5KBuHky7wBwbPiI0pTmEwvd7i7hW9Uqs Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=modlfo@gmail.com; spf=Pass smtp.mailfrom=modlfo@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f169.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of modlfo@gmail.com) identity=pra; client-ip=209.85.223.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="modlfo@gmail.com"; x-sender="modlfo@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of modlfo@gmail.com designates 209.85.223.169 as permitted sender) identity=mailfrom; client-ip=209.85.223.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="modlfo@gmail.com"; x-sender="modlfo@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-io0-f169.google.com) identity=helo; client-ip=209.85.223.169; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="modlfo@gmail.com"; x-sender="postmaster@mail-io0-f169.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CfAgAZYPlVm6nfVdFdg3dpqRUGiC+NXIYBAoFAPBABAQEBAQEBARABAQEBAQYLCwkhLoIdggcBAQQSEQQLAQUIARscAgMMBgULDQICBRYLAgIJAwIBAgEREQEFARwTCAEBHod2AQMSBAGnPYEwPjGLRoFsgnmKJAoZJw1WhAwBAQgCGgEFDoEUhQqEPoEGhFo6F4JSgUMBBJVehRCHc4IThl0QkEQ1gRc4gi+Bf2+KKgEBAQ X-IPAS-Result: A0CfAgAZYPlVm6nfVdFdg3dpqRUGiC+NXIYBAoFAPBABAQEBAQEBARABAQEBAQYLCwkhLoIdggcBAQQSEQQLAQUIARscAgMMBgULDQICBRYLAgIJAwIBAgEREQEFARwTCAEBHod2AQMSBAGnPYEwPjGLRoFsgnmKJAoZJw1WhAwBAQgCGgEFDoEUhQqEPoEGhFo6F4JSgUMBBJVehRCHc4IThl0QkEQ1gRc4gi+Bf2+KKgEBAQ X-IronPort-AV: E=Sophos;i="5.17,539,1437429600"; d="scan'208";a="177873988" Received: from mail-io0-f169.google.com ([209.85.223.169]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 Sep 2015 14:28:13 +0200 Received: by ioiz6 with SMTP id z6so227941255ioi.2 for ; Wed, 16 Sep 2015 05:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=rXGNYPxyvapl0ggA95LLi4RHMIikNojbgOnViTLGCLE=; b=eZyKJzHF8YJA9jeTqJ99iX34NLzNcLh2MGMGe+oaufOT0Fk80tHT2Rn5X5KpoXb2S6 /vVOzHIQrm5bw1uVFZB4JC9/cQByZfdJssL1u7FHpjDNuUUodRmfuuTDWlfl5P4Z62JA F/Zt3xnyrXpxX9+OGfxLP5gyWod25g0A54SAy5oXjxxwHsk9kell6Ka4qXo4/gLDv9Wb ef6TFWWM73Us6G/Ht//nUro18Ft6YuQstDOurz3+IHdehDrqYIflgvrqv3gDLdedbg8n 4fEsqxyhqRICAjGwp4ivXgEOsaFBn8gm27scNL860VgUv2ccUziCUaTbjEyRMq7d4i7C mm1g== X-Received: by 10.107.135.196 with SMTP id r65mr32068343ioi.131.1442406492203; Wed, 16 Sep 2015 05:28:12 -0700 (PDT) Received: from [10.10.156.106] ([94.136.92.222]) by smtp.googlemail.com with ESMTPSA id 39sm10232032ioh.38.2015.09.16.05.28.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 05:28:10 -0700 (PDT) To: caml-list@inria.fr References: <55F95E5E.6000209@gmail.com> <55F96004.4010001@gmail.com> From: Leonardo Laguna Ruiz Message-ID: <55F9605C.9060207@gmail.com> Date: Wed, 16 Sep 2015 14:28:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55F96004.4010001@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Pattern matching of records Great! thank you very much guys! Leonardo On 2015-09-16 14:26, Thibault Suzanne wrote: > There is no need to specify the origin module in front of each field : > > match s0 with > | { S.a = 0; b = 0 } -> true > | _ -> false > > Le 16/09/2015 14:19, Leonardo Laguna Ruiz a écrit : >> >> 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 >> >> >> > >