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 6792A7EEBF for ; Tue, 18 Aug 2015 15:00:58 +0200 (CEST) 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.223.171; 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.223.171 as permitted sender) identity=mailfrom; client-ip=209.85.223.171; 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-io0-f171.google.com) identity=helo; client-ip=209.85.223.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f171.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BfAwA2K9NVlKvfVdFdg29pBoMeqieEboshgiABCYV5AoEnB0wBAQEBAQESAQEBAQcLCwkfMIQjAQEBAwEBAg8RHQEbEgsBAwELBgULAwoNHQICIgERAQUBChIGEwgKCAiHdgEDCggNrRGBLz4xi0CBbIJ5iyAKGScDCleFAAEBAQEBBQEBAQEBAQEVAQUOi0SFBQQHgmmBQwWFbAyPKIUEh2iCEJZTEiOBFxEGgh0cgVU8M4JMAQEB X-IPAS-Result: A0BfAwA2K9NVlKvfVdFdg29pBoMeqieEboshgiABCYV5AoEnB0wBAQEBAQESAQEBAQcLCwkfMIQjAQEBAwEBAg8RHQEbEgsBAwELBgULAwoNHQICIgERAQUBChIGEwgKCAiHdgEDCggNrRGBLz4xi0CBbIJ5iyAKGScDCleFAAEBAQEBBQEBAQEBAQEVAQUOi0SFBQQHgmmBQwWFbAyPKIUEh2iCEJZTEiOBFxEGgh0cgVU8M4JMAQEB X-IronPort-AV: E=Sophos;i="5.15,701,1432591200"; d="scan'208";a="173965029" Received: from mail-io0-f171.google.com ([209.85.223.171]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Aug 2015 15:00:57 +0200 Received: by iodt126 with SMTP id t126so188359207iod.2 for ; Tue, 18 Aug 2015 06:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=l7e9rIZDthVs0J9GKYGpn70vvrQj0emSeJPqbLpD/8E=; b=MmSIAPSoNdqAb1Wa5I3Lo4Fq8sLkobK7V3IAMFVOBukGqrdUvy6psfdXkXbwSqvvTb jwZmpcD/M3IJ6U5wScr7r+j6wt09VfYEcGx94faCgtpXYdvwsAui8FSVyzKqIFIgFDZc sZNQ2Z6CT0zwJdt8jR2WWGOHjCUZ6tMdaDoSfLIwmANMVMmWtlm3uQ3AUmgxf6tU2LDk N36/roY0HIavvgZPZSto9rc0skQk8Ez5V0+q2kp8636LbftNTlpZf21EVYa5lqOVW6Ih Jcb5plKNdnITJA7CWLDGvt6S7NqsRJ2gF8LO0K3YftjHLboW0SKZ/w15E0Hv69wtWTrT X6jg== X-Received: by 10.107.13.201 with SMTP id 192mr6978391ion.70.1439902856054; Tue, 18 Aug 2015 06:00:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.68.132 with HTTP; Tue, 18 Aug 2015 06:00:16 -0700 (PDT) In-Reply-To: References: <55BF75F6.1040006@bioquant.uni-heidelberg.de> <8E1A640CE3374EB492981ADB0A2DA5C6@erratique.ch> <20150804092633.GC5689@frosties> <5C2023F4AF0549F58F3E4C9A6F8ABE84@erratique.ch> <20150814105551.GD31364@frosties> <55CDD0F2.1090200@zoho.com> <20150818111134.GA11154@frosties> From: Gabriel Scherer Date: Tue, 18 Aug 2015 15:00:16 +0200 Message-ID: To: David Allsopp Cc: Goswin von Brederlow , "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=001a113fd5e03f305d051d95828c Subject: Re: [Caml-list] destructive local opens --001a113fd5e03f305d051d95828c Content-Type: text/plain; charset=UTF-8 Note that the dual feature does not exist for variant constructors, because it is easy to define only on the constructor at the toplevel of the pattern, and nested patterns get us in muddy waters. On Tue, Aug 18, 2015 at 2:52 PM, David Allsopp wrote: > Goswin von Brederlow wrote: > > On Fri, Aug 14, 2015 at 01:28:50PM +0200, Drup wrote: > > > > > > >You can't qualifylocal values or values of the surrounding module so > > > >that is a no go. > > > > > > > >I also often use local open to access records, as in: > > > > > > > >let r = M.({ x = 1; y; z = depth; }) in > > > > > > You can avoid the local open altogether and write it like that: > > > > > > let r = {M. x = 1; y; z = depth } in > > > > > > It's even shorter. > > > > That only works because newer ocaml disambiguises (is that a word?) > record > > So it's implicitly using M.y = y and M.z = depth. > > labels when it determines the record type from the first label, right? > > Only since you ask: "disambiguates" :o) That said, it's quite common to > see words like "disambiguises" being invented by Americans! > > But this isn't related to the disambiguation features of OCaml 4.01+. > Those allow you to write things like: > > type t = {x : int} > type u = {x : int; y : string} > > let foo = {x = 1} > let bar = {x = 42; y = ""} > > This is actually a much older notation added in OCaml 3.08. Prior to that, > if you hadn't opened a module you had to qualify each label: > > {M.x = 1; M.y = y; M.z = depth} > > but this was "silly", since it's not possible to use non-equivalent module > paths for labels, so OCaml 3.08 changed it so that you only needed to put > the module path on one label (and it doesn't have to be the first one, it's > just a bit weird to put it in the middle!). > > OCaml 3.12 added, amongst other record-related goodies, the shorthand {y} > to mean {y = y}. So while you can use local open as you're using it, you've > been able to do it as a totally unambiguous language feature for quite some > time. > > > David > > > -- > 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 > --001a113fd5e03f305d051d95828c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Note that the dual feature does not exist for variant cons= tructors, because it is easy to define only on the constructor at the tople= vel of the pattern, and nested patterns get us in muddy waters.

On Tue, Aug 18, 201= 5 at 2:52 PM, David Allsopp <dra-news@metastack.com> wr= ote:
Goswin von Brederlo= w wrote:
> On Fri, Aug 14, 2015 at 01:28:50PM +0200, Drup wrote:
> >
> > >You can't qualifylocal values or values of the surroundin= g module so
> > >that is a no go.
> > >
> > >I also often use local open to access records, as in:
> > >
> > >let r =3D M.({ x =3D 1; y; z =3D depth; }) in
> >
> > You can avoid the local open altogether and write it like that: > >
> >=C2=A0 =C2=A0 =C2=A0let r =3D {M. x =3D 1; y; z =3D depth } in
> >
> > It's even shorter.
>
> That only works because newer ocaml disambiguises (is that a word?) re= cord
> So it's implicitly using M.y =3D y and M.z= =3D depth.
> labels when it determines the record type from the first label, right?=

Only since you ask: "disambiguates" :o) That said, it'= s quite common to see words like "disambiguises" being invented b= y Americans!

But this isn't related to the disambiguation features of OCaml 4.01+. T= hose allow you to write things like:

type t =3D {x : int}
type u =3D {x : int; y : string}

let foo =3D {x =3D 1}
let bar =3D {x =3D 42; y =3D ""}

This is actually a much older notation added in OCaml 3.08. Prior to that, = if you hadn't opened a module you had to qualify each label:

{M.x =3D 1; M.y =3D y; M.z =3D depth}

but this was "silly", since it's not possible to use non-equi= valent module paths for labels, so OCaml 3.08 changed it so that you only n= eeded to put the module path on one label (and it doesn't have to be th= e first one, it's just a bit weird to put it in the middle!).

OCaml 3.12 added, amongst other record-related goodies, the shorthand {y} t= o mean {y =3D y}. So while you can use local open as you're using it, y= ou've been able to do it as a totally unambiguous language feature for = quite some time.


David


--
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

--001a113fd5e03f305d051d95828c--