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 0A7AA7FD90 for ; Thu, 15 Dec 2016 16:09:17 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-it0-f41.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.41 as permitted sender) identity=mailfrom; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@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-it0-f41.google.com) identity=helo; client-ip=209.85.214.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-it0-f41.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A3hrGHxxBEJxQ6xbXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0esfIJqq85mqBkHD//Il1AaPBtSArawUwLCK++C4ACpbvsbH6ChDOLV3FDY7yu?= =?us-ascii?q?wu1zQ6B8CEDUCpZNXLVAcdWPp4aVl+4nugOlJUEsutL3fbo3m18CJAUk6nbVk9?= =?us-ascii?q?Dq3PF4XTl8W60fyps92WOl0QxWn1XbQnAxy8twTcsoEziJp4YvI+wxHTo3ZMPe?= =?us-ascii?q?Ff1HlAIFuSm1Dw65Hj0oRk9nF/svg79sNEGZ7xf6kiQKYQWDsvOXo06cmtrhLD?= =?us-ascii?q?QBGC/FMTV2wXllxDBA2Tv0KyZYv4riav7rk14yKdJ8CjCOlsATk=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AZAwBmsVJYhinWVdFUCRoBAQEBAgEBA?= =?us-ascii?q?QEIAQEBARYBAQEDAQEBCQEBAYMMAQEBAQE/OoEGB6QeiGWDfYMEhy0ihgACgX4?= =?us-ascii?q?HQxABAQEBAQEBAQEBARIBAQEICwsJHTCCMwQBFQEEghcBBAEjBBkBGx0BAwwGB?= =?us-ascii?q?QQHNwICIgERAQUBHAYTiFABAw8InGE/jAKBbBgFAR6DDQWDWwoZJw0ITIJ4AQE?= =?us-ascii?q?BAQEBBAEBAQEBAQEZAgYShiSEWYJUgUUKAQFIgleCXQWIY4cbim6BeYRYimKCR?= =?us-ascii?q?Y4GjhSCSRQegRQ2UVBKE4MyIIIGIDSGPl+BTwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0AZAwBmsVJYhinWVdFUCRoBAQEBAgEBAQEIAQEBARYBAQE?= =?us-ascii?q?DAQEBCQEBAYMMAQEBAQE/OoEGB6QeiGWDfYMEhy0ihgACgX4HQxABAQEBAQEBA?= =?us-ascii?q?QEBARIBAQEICwsJHTCCMwQBFQEEghcBBAEjBBkBGx0BAwwGBQQHNwICIgERAQU?= =?us-ascii?q?BHAYTiFABAw8InGE/jAKBbBgFAR6DDQWDWwoZJw0ITIJ4AQEBAQEBBAEBAQEBA?= =?us-ascii?q?QEZAgYShiSEWYJUgUUKAQFIgleCXQWIY4cbim6BeYRYimKCRY4GjhSCSRQegRQ?= =?us-ascii?q?2UVBKE4MyIIIGIDSGPl+BTwEBAQ?= X-IronPort-AV: E=Sophos;i="5.33,352,1477954800"; d="scan'208,217";a="250244908" Received: from mail-it0-f41.google.com ([209.85.214.41]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 15 Dec 2016 16:09:16 +0100 Received: by mail-it0-f41.google.com with SMTP id y23so32421938itc.0 for ; Thu, 15 Dec 2016 07:09:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0KN9h0bcymHb5XIxvTEb7x21ybjhTKCysrGtQ9hiAhs=; b=J9W5o22aWAR0vVGxcoDR8ScjHsZHstv2KED26ZQkkJRMBJhzmjyGC7At1Kj3ZynsB2 ECK3wodqCtAKbmbPigEB4mXm0KYeiYYkLREXSW7K+0TgouW8e5g91OLYVi+5hnZd4j2g F7B9cVWxg8+Sx+gtBtpRC2kS+2ThY5nV8XYNJQPmCV39H1uIbSQquXwOhLL509gCMpNk Xwu9Sh8bE/wEjhChNSGGg+YH2iSUru83R5jGBm7ENYYA9OYROj4wqz0mokqVoPc8e360 vxdWj17Ohn61ecAsx2wjpHdqum8Lph3Uuk/vUKUmuchiINuJHQFyEt6pxX981IMzWZTW MUDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0KN9h0bcymHb5XIxvTEb7x21ybjhTKCysrGtQ9hiAhs=; b=rqiOdsLrx86Ys9LyzQiBa6sluaVLalUWebb5NWvbS1FzkGck1lxmUQqvswpLvoAx/f F/6udjGChFSAIZCyDl12v1m3kyxd5Fv8zP8oYOnSoDJnDdrY76TSiV4ipWY8JgKtLznZ wqaU3FZmezXXAjm8KQpQzajFx1bUWB0cY3fZBplHa/uGQ4co/YCKO9RBgPaLGKemYL1A N3AfC5OmDxNpTXzWENS59xwPdPyF5jDFcwgt4skH+r5hMVFWvr68ooXlFgOKkX7RnLMD +WQt+Zpri+mGeixfLU5fvJMTZv88ZFAZBtLXBwMJi6RYzDCcKgQVvWtAv04Z2pC83S6u X+VQ== X-Gm-Message-State: AKaTC02RNyElCtcyg+X0k8S+yKy8HaMtfpC0DEY+/kqt/8n4dw5BlVm3DmecHxf9Vu4rg0E7TgTZhjbJM2WnmA== X-Received: by 10.36.217.79 with SMTP id p76mr1837924itg.16.1481814554840; Thu, 15 Dec 2016 07:09:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.140.146 with HTTP; Thu, 15 Dec 2016 07:08:34 -0800 (PST) In-Reply-To: <20161215141240.01BE740092@smtp03.mail.de> References: <20161215141240.01BE740092@smtp03.mail.de> From: Gabriel Scherer Date: Thu, 15 Dec 2016 10:08:34 -0500 Message-ID: To: Gabriel Mayr Cc: caml users Content-Type: multipart/alternative; boundary=001a1145ed9e2a12240543b3d67b Subject: Re: [Caml-list] unnamed records in match on multiple constructors --001a1145ed9e2a12240543b3d67b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable The issue is "what is the type of an inline record"? Internally each inline record in a constructor declaration has its own type, so in particular two different records have distinct types. One way to think of it is that type t =3D A of {i:int} | B of {i:int};; is morally equivalent to type t_internal_A =3D {i : int};; type t_internal_B =3D {i : int};; type t =3D A of t_internal_A | B of t_internal_B;; And then (function (A e | B e) -> e.i) does not type-check either -- with the same error message. This comes from the fact that, in OCaml (unlike in SML), records are nominal, have an identity: declaring another record type with the same fields creates a new, incompatible type. So the answer is: this is a natural, expected consequence of how inline records and how records work in OCaml. On Thu, Dec 15, 2016 at 9:12 AM, Gabriel Mayr wrote: > > Hi, > > I'm using utop version 1.19.3 (using OCaml version 4.03.0). > > Using an *named* record in a type definition and afterwards match on > multiple constructors *works:* > # type a =3D {i:int};; > #type t =3D A of a | B of a;; > # let x =3D A {i=3D10};; > # match x with > | A e | B e -> print_int e.i;; > > > Using an *unnamed* record in a type definition and afterwards match on > multiple constructors *does not work:* > # type t =3D A of {i:int} | B of {i:int};; > # let x =3D A {i=3D10};; > # match x with > | A e | B e -> print_int e.i;; > > "Error: The variable e on the left-hand side of this or-pattern has type > t.A but on the right-hand side it has type t.B" > > > > I don't know if this is behaviour of OCaml is desired or it's a fault. > > Hope I could help you with this little hint. > > Best regards, > > Gabriel > > ------------------------------ > FreeMail powered by mail.de - *mehr Sicherheit, Seriosit=C3=A4t und Komfo= rt* --001a1145ed9e2a12240543b3d67b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The issue is "what is the type of an inline record&qu= ot;? Internally each inline record in a constructor declaration has its own= type, so in particular two different records have distinct types. One way = to think of it is that

=C2=A0 type t =3D A of {i:int} | B of {i:int};;

is m= orally equivalent to

=C2=A0 type t_internal_A =3D {i : in= t};;
=C2=A0 type t_internal_B =3D {i : int};;
= =C2=A0 type t =3D A of t_internal_A | B of t_internal_B;;

And then (function (A e | B e) -> e.i) does not type-check either -- wi= th the same error message. This comes from the fact that, in OCaml (unlike = in SML), records are nominal, have an identity: declaring another record ty= pe with the same fields creates a new, incompatible type.

So the answer is: this is a natural, expected consequence of how inline re= cords and how records work in OCaml.

On Thu, Dec 15, 2016 at 9:12 AM, Gabriel Mayr <gabriel.mayr@mail.de> wrote:
=C2=A0
Hi,
=C2=A0
I'm using utop version 1.19.3 (using OCaml version 4.03.0).
=C2=A0
Using an named record in a type definition and afterwards match= on multiple constructors works:
# type a =3D {i:int};;
#type t =3D A of a | B of a;;
# let x =3D A {i=3D10};;
# match x with
| A e | B e -> print_int e.i;;
=C2=A0
=C2=A0
Using an unnamed record in a type definition and afterwards mat= ch on multiple constructors does not work:
# type t =3D A of {i:int} | B of {i:int};;
# let x =3D A {i=3D10};;
# match x with
| A e | B e -> print_int e.i;;

"Error: The variable e on the left-hand side of this or-patte= rn has type t.A but on the right-hand side it has type t.B"
=C2=A0
=C2=A0
=C2=A0
I don't know if this is behaviour of OCaml is desired or it's = a fault.
=C2=A0
Hope I could help you with this little hint.
=C2=A0
Best regards,
=C2=A0
Gabriel


FreeMail powered by mail.de - mehr Sicherheit, Seriosit=C3=A4t und Komf= ort

--001a1145ed9e2a12240543b3d67b--