From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0E12BBBAF for ; Tue, 20 Jan 2009 14:25:52 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At8AAHtfdUnVhjEYkWdsb2JhbACUBQEBAQEJCwoHEQO2XIJLgyg X-IronPort-AV: E=Sophos;i="4.37,295,1231110000"; d="scan'208";a="19894805" Received: from ihsmtp02voda.lis.interhost.com (HELO ihsmtp02cons.lis.interhost.com) ([213.134.49.24]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Jan 2009 14:25:51 +0100 Received: from [192.168.1.64] ([77.54.249.136]) by ihsmtp02cons.lis.interhost.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 20 Jan 2009 13:23:13 +0000 Message-ID: <4975D0D9.4060207@inescporto.pt> Date: Tue, 20 Jan 2009 13:25:45 +0000 From: Hugo Ferreira User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: Thomas Gazagnaire Cc: David Teller , OCaml List Subject: Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature References: <4975AEA2.6050901@inescporto.pt> <1232451451.6272.71.camel@Blefuscu> <4975B9A4.7020609@inescporto.pt> <9722eaea0901200456v6b7b4b3doa11c8b1ea4dfee98@mail.gmail.com> In-Reply-To: <9722eaea0901200456v6b7b4b3doa11c8b1ea4dfee98@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 20 Jan 2009 13:23:13.0436 (UTC) FILETIME=[3F073DC0:01C97B02] X-Spam: no; 0.00; functorize:01 sig:01 struct:01 sig:01 node:01 node:01 val:01 bool:01 val:01 hash:01 struct:01 hash:01 hashtbl:01 hashtbl:01 abstr:01 Thomas Gazagnaire wrote: > Or you can also functorize your own piece of code : > > module Make (A : sig type t end) = > struct > > module rec H : > sig > type 'a node = > | Node of 'a node J.t > | Leaf of 'a > > type t = A.t node > val equal : t -> t -> bool > val hash : t -> int > end = > struct > type 'a node = > | Node of 'a node J.t > | Leaf of 'a > > type t = A.t node > let equal = (==) > let hash = Hashtbl.hash > end > > and J : Hashtbl.S with type key = A.t H.node = Hashtbl.Make( H ) > > end > Incredible! You have just provided a excellent solution. Works "out of the box": # module N = Make(struct type t = int end ) ;; # let jls = J.create 13 ;; val jls : '_a N.J.t = # let r = H.Node(jls) ;; val r : '_a N.H.node = N.H.Node # let _ = J.add jls r r ;; - : unit = () # let x = J.find jls r ;; val x : int N.H.node = N.H.Node # let r = (x == r ) ;; val r : bool = true Hmmm... now I wonder if that node type can also be pulled in by the functor. If so we have a very general solution to the problem of equality checking of polymorphic types. Anyone care to comment? Once again Thomas, thank you. Hugo F. > 2009/1/20 Hugo Ferreira > > > David Teller wrote: > > It's probably feasible without copy & paste by building a > functor on top > of the defunctorized hashtable in Batteries. Or by just using the > defunctorized hashtable of Batteries directly, although it's not > as safe > as the functorized version, due to the absence of existential types. > > > If I understand you correctly I would have to redefine equivalents for: > - HashedType > - S > - Make(H: HashedType) > > Basically copy & paste these and change the type. > Doable although not to my liking. > > TIA, > Hugo F. > > > > Cheers, > David > > On Tue, 2009-01-20 at 12:24 +0100, Daniel Bünzli wrote: > > Le 20 janv. 09 à 11:59, Hugo Ferreira a écrit : > > Is it possible to make H comply with Hashtbl.HashedType > i.e: make > J.Key = 'a H.node ? > > This issue is well known (e.g. see here [1]). Your are > running into limitations of the standard library. The only > unsatisfying answer is to copy the code from the standard > library and add the parameter yourself. > > Best, > > Daniel > > [1] > http://groups.google.com/group/fa.caml/browse_thread/thread/f2acb593da91553c?hl=fr&ie=UTF-8&q=type+var+in+functor+fa.caml > > > ____________________________________________ugs > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >