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 74BD67FC53 for ; Tue, 29 Sep 2015 17:14:03 +0200 (CEST) IronPort-PHdr: 9a23:ISPhPRzH4Z4dQ8zXCy+O+j09IxM/srCxBDY+r6Qd0eIQIJqq85mqBkHD//Il1AaPBtWHra8bwLqL+4nbGkU+or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkItf6KuStKU0pv8h7360qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45javAPES0Oq530HUXRexgtNAg7e7wDSXJ73vzDmrOdwxG+ROsigHp4uXjH3wK5hUh7ljG88PD406mzNwph/hahBoR+l4Qd0w4PObZu9O/93f6ebdtQfEzkSFv1NXjBMV9vvJ7AECPAMaKMB99Hw 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-io0-f171.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.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: A0AIAgAMqgpWlKvfVdFeg3hpBoMkukmBe4V5AoFHBzoSAQEBAQEBAQEQAQEBAQcLCwkfMIIdggcBAQEDARIRHQEbHQEDAQsGBQQHAwoqAgIhAQERAQUBHAYTIod2AQMKCA2pKIEwPjGLR4FsgnmKFgoZJw1WhDIBAQEBAQEEAQEBAQEBARUBAQQOhmWEfYJQgjkEB4JpgUMFlXSFFoYNgXCTfIV8EiOBFygBgj4MHYFWPDMBiR4BAQE X-IPAS-Result: A0AIAgAMqgpWlKvfVdFeg3hpBoMkukmBe4V5AoFHBzoSAQEBAQEBAQEQAQEBAQcLCwkfMIIdggcBAQEDARIRHQEbHQEDAQsGBQQHAwoqAgIhAQERAQUBHAYTIod2AQMKCA2pKIEwPjGLR4FsgnmKFgoZJw1WhDIBAQEBAQEEAQEBAQEBARUBAQQOhmWEfYJQgjkEB4JpgUMFlXSFFoYNgXCTfIV8EiOBFygBgj4MHYFWPDMBiR4BAQE X-IronPort-AV: E=Sophos;i="5.17,608,1437429600"; d="scan'208";a="179997733" Received: from mail-io0-f171.google.com ([209.85.223.171]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Sep 2015 17:14:02 +0200 Received: by ioii196 with SMTP id i196so14064817ioi.3; Tue, 29 Sep 2015 08:14:01 -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=LBIMh5RvmpBmBXjUL1VtE7AF5zfj+lfJfn1d7+uG6TY=; b=arettjo3YxL10W5dEEdQMMTFWaPgiiA7TMA0G82tg0wIo/denzeqODJERBz6oPHpvG nX1fE9Wy4BjJbFNi+U0WzaqnEkkqai6QqhivEBvf8iG1q/0pWGLtSuMN5GIhoNkdEGpG aOvC9fk12Mwh62l5YcHDGpOw47YfJGTTPohF9Gh9DYtJtpjVwrTpGCAT+ZFMM1RQrW7Y qT8sNlKqBDOQVnQ3edLgULZ5KWvetDNM4bBVEqUY+ogksaxpibbNVUzfXxHTwe+AhHKV RpasLdVa7BXeKX5OrsVnn/6R9mAxx+pbfqP14nBLpOOqhVurZN+uJao6WdfCQPslITf5 JMcg== X-Received: by 10.107.40.12 with SMTP id o12mr26406603ioo.84.1443539641467; Tue, 29 Sep 2015 08:14:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.19.68 with HTTP; Tue, 29 Sep 2015 08:13:22 -0700 (PDT) In-Reply-To: References: <20150929124344.GA13383@pl-59055.rocqadm.inria.fr> From: Gabriel Scherer Date: Tue, 29 Sep 2015 17:13:22 +0200 Message-ID: To: Yaron Minsky Cc: Jesper Louis Andersen , =?UTF-8?Q?S=C3=A9bastien_Hinderer?= , caml users Content-Type: multipart/alternative; boundary=001a1141d1508ca6f00520e443cc Subject: Re: [Caml-list] polymorphic sets? --001a1141d1508ca6f00520e443cc Content-Type: text/plain; charset=UTF-8 Indeed. With functors one uses the path equality check as a way to enforce coherence, with a phantom type you can let people build their own phantom paths and use them to mark type (in)compatibility. This is slightly less safe (in the sense that users can always break that promise if they want to by behaving badly -- but I think this is fine), but also easier to use (than the module language) and more flexible in some cases. On Tue, Sep 29, 2015 at 4:52 PM, Yaron Minsky wrote: > Core_kernel's maps and sets solve this problem, and address Gabriel's > concern as well, by providing type witnesses that distinguish maps > built with different comparators. There's an introduction to the use > of these modules here: > > > > and you can see the current APIs here: > > > > Sets are handled similarly.For sure, better inlining (as is coming in > Flambda!) can make this approach better. > > y > > On Tue, Sep 29, 2015 at 9:56 AM, Jesper Louis Andersen > wrote: > > > > On Tue, Sep 29, 2015 at 2:58 PM, Gabriel Scherer < > gabriel.scherer@gmail.com> > > wrote: > >> > >> Note that the polymorphic sets (or maps) are less statically-safe than > >> their functorized counterpart, because they are parametrized over their > >> comparison function at creation time > > > > > > The only point in time I've had troubles is when you have a map where its > > values and keys range over a type that can recursively contain that map > of > > the same type. This required a polymorphic compare (from Core) to pull > off. > > > > > > -- > > J. > --001a1141d1508ca6f00520e443cc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Indeed. With functors one uses the path equality check as = a way to enforce coherence, with a phantom type you can let people build th= eir own phantom paths and use them to mark type (in)compatibility. This is = slightly less safe (in the sense that users can always break that promise i= f they want to by behaving badly -- but I think this is fine), but also eas= ier to use (than the module language) and more flexible in some cases.
<= /div>

On Tue, Sep = 29, 2015 at 4:52 PM, Yaron Minsky <yminsky@janestreet.com> wrote:
Core_kernel's maps and set= s solve this problem, and address Gabriel's
concern as well, by providing type witnesses that distinguish maps
built with different comparators.=C2=A0 There's an introduction to the = use
of these modules here:

<https://realworldocaml.org/v1/en/= html/maps-and-hash-tables.html>

and you can see the current APIs here:

<https://github.com/janestr= eet/core_kernel/blob/master/src/core_map.mli>

Sets are handled similarly.For sure, better inlining (as is coming in
Flambda!) can make this approach better.

y

On Tue, Sep 29, 2015 at 9:56 AM, Jesper Louis Andersen
<jesper.louis.anderse= n@gmail.com> wrote:
>
> On Tue, Sep 29, 2015 at 2:58 PM, Gabriel Scherer <gabriel.scherer@gmail.com>
> wrote:
>>
>> Note that the polymorphic sets (or maps) are less statically-safe = than
>> their functorized counterpart, because they are parametrized over = their
>> comparison function at creation time
>
>
> The only point in time I've had troubles is when you have a map wh= ere its
> values and keys range over a type that can recursively contain that ma= p of
> the same type. This required a polymorphic compare (from Core) to pull= off.
>
>
> --
> J.

--001a1141d1508ca6f00520e443cc--