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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 6AF2E7F790 for ; Thu, 24 Apr 2014 16:28:39 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.17.12; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhEBANMeWVPU4xEMnGdsb2JhbAA/GoNVxQ2BGRYOAQEBAQEGDQkJFCiCJQEBBScTTwsYCSUPBSg0iCwBGAk2w08fhw4Xjl8Wgw6BFQSYdIE5hQwSjzM X-IPAS-Result: AhEBANMeWVPU4xEMnGdsb2JhbAA/GoNVxQ2BGRYOAQEBAQEGDQkJFCiCJQEBBScTTwsYCSUPBSg0iCwBGAk2w08fhw4Xjl8Wgw6BFQSYdIE5hQwSjzM X-IronPort-AV: E=Sophos;i="4.97,919,1389740400"; d="scan'208";a="58761822" Received: from mout.web.de ([212.227.17.12]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Apr 2014 16:28:38 +0200 Received: from frosties.localnet ([78.43.112.61]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0Lym5H-1X0vAX0SEZ-0166gG for ; Thu, 24 Apr 2014 16:28:38 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1WdKdh-00015P-Hg for caml-list@inria.fr; Thu, 24 Apr 2014 16:28:37 +0200 Date: Thu, 24 Apr 2014 16:28:37 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140424142837.GA3845@frosties> References: <5356225B.1090305@cryptosense.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V03:K0:pZo9uxmzBAM6s61KRWF1iHqYZqmHkIgO6rc52/dkRG8DRdQ1i/X YXBsCF2yybpgSi4H3OI6OZ4b9XaEZXqGUS9hBaPVeGcE7/14teJIrfP/SCG17Mbukuyq4OM 4KQolC4hzitSGB1d0qdd0mh1om30Uo45OeJvIWTNHVd+osovBbb67ZIxFRSQ4IfHSDq6q6a ArxSavdugrqqjxdOvN9RQ== Subject: Re: [Caml-list] Obj.magic for polymorphic identifiers On Tue, Apr 22, 2014 at 09:31:13AM +0100, Jeremie Dimino wrote: > On Tue, Apr 22, 2014 at 9:03 AM, Romain Bardou wrote: > > > I want to implement the trick with GADTs where you test equality of > > unique identifiers, and if they match this adds an equality constraint > > on types. I want this code to be small and well abstracted in a module > > so that if this module is safe, then using this module cannot cause a > > seg fault. > > > > Here is the signature of my module: > > [...] > > > > We do exactly this at Jane Street in our type_equal module: > > https://github.com/janestreet/core_kernel/blob/master/lib/type_equal.ml#L87 > > Note that using the open_types branch of ocaml [1] there is a cool way to > do this: > > (************************************************************************) > type 'a key = .. > > type (_, _) equal = > | Equal: ('a, 'a) equal > | Different: ('a, 'b) equal > > module type S = sig > type t > type 'a key += T : t key > end > > type 'a t = (module S with type t = 'a) > > let fresh (type a) () = > let module M = struct > type t = a > type 'a key += T : t key > end in > (module M : S with type t = a) > > let equal (type a) (type b) > (module A : S with type t = a) > (module B : S with type t = b) > : (a, b) equal = > match A.T with > | B.T -> Equal > | _ -> Different > > let to_int = Hashtbl.hash > (************************************************************************) > > [1] http://caml.inria.fr/mantis/view.php?id=5584 > > -- > Jeremie Now that is a good reason to have open types. I've tried (and failed) to do something like this without resorting to magic and the only way I found was to declare a big GADT that has a constructor for every possible type and match all possible equal pairs. That realy doesn't scale well. Would it be possible for someone familiar with the patch to create a pull request for it on git? Maybe that way it could be merged in faster. MfG Goswin