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=0.0 required=5.0 tests=HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 8A376BBAF for ; Tue, 20 Jan 2009 13:58:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgABAClZdUnRVdoNkWdsb2JhbACCQS6QWD4BAQEBCQkMBw+2YoJLgyg X-IronPort-AV: E=Sophos;i="4.37,295,1231110000"; d="scan'208";a="21767956" Received: from mail-bw0-f13.google.com ([209.85.218.13]) by mail3-smtp-sop.national.inria.fr with ESMTP; 20 Jan 2009 13:58:33 +0100 Received: by bwz6 with SMTP id 6so153084bwz.20 for ; Tue, 20 Jan 2009 04:58:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.181.144.10 with SMTP id w10mr608524bkn.84.1232456196699; Tue, 20 Jan 2009 04:56:36 -0800 (PST) In-Reply-To: <4975B9A4.7020609@inescporto.pt> References: <4975AEA2.6050901@inescporto.pt> <1232451451.6272.71.camel@Blefuscu> <4975B9A4.7020609@inescporto.pt> Date: Tue, 20 Jan 2009 12:56:36 +0000 Message-ID: <9722eaea0901200456v6b7b4b3doa11c8b1ea4dfee98@mail.gmail.com> Subject: Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature From: Thomas Gazagnaire To: Hugo Ferreira Cc: David Teller , OCaml List Content-Type: multipart/alternative; boundary=001636499007ce371b0460e9912f X-Spam: no; 0.00; ocaml:01 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 --001636499007ce371b0460e9912f Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Or you can also functorize your own piece of code : module Make (A : sig type t end) =3D struct module rec H : sig type 'a node =3D | Node of 'a node J.t | Leaf of 'a type t =3D A.t node val equal : t -> t -> bool val hash : t -> int end =3D struct type 'a node =3D | Node of 'a node J.t | Leaf of 'a type t =3D A.t node let equal =3D (=3D=3D) let hash =3D Hashtbl.hash end and J : Hashtbl.S with type key =3D A.t H.node =3D Hashtbl.Make( H ) end 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=FCnzli wrote: >> >>> Le 20 janv. 09 =E0 11:59, Hugo Ferreira a =E9crit : >>> >>> Is it possible to make H comply with Hashtbl.HashedType i.e: make >>>> J.Key =3D '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/f2acb593da9= 1553c?hl=3Dfr&ie=3DUTF-8&q=3Dtype+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 > --001636499007ce371b0460e9912f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Or you can also functorize your own piece of code :

module Make (A := sig type t end) =3D
struct

    module rec H :     sig
        type '= a node =3D
            | No= de of 'a node J.t
          =   | Leaf of 'a
               =  
        type t =3D A.t node
&n= bsp;       val equal : t -> t -> bool
&nb= sp;       val hash : t -> int
  &n= bsp; end =3D
    struct
      = ;  type 'a node =3D
         = ;   | Node of 'a node J.t
            | Leaf of 'a              &nbs= p;  
        type t =3D A.t node
=         let equal =3D (=3D=3D)
  = ;      let hash =3D Hashtbl.hash
    = end
       
    and J := Hashtbl.S with type key =3D A.t H.node =3D Hashtbl.Make( H )
   
end

2009/1/20 Hugo= Ferreira <hmf@in= escporto.pt>
David Teller wrote:
It's probably feasible without copy & paste by building a functor o= n top
of the defunctorized hashtable in Batteries. Or by just using the
defunctorized hashtable of Batteries directly, although it's not as saf= e
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=FCnzli wrote:
Le 20 janv. 09 =E0 11:59, Hugo Ferreira a =E9crit :

Is it possible to make H comply with Hashtbl.HashedType i.e: make
J.Key =3D 'a H.node ?
This issue is well known (e.g. see here [1]). Your are running into  l= imitations of the standard library. The only unsatisfying answer is  t= o copy the code from the standard library and add the parameter  yours= elf.

Best,

Daniel

[1] http://groups.google.com/group/fa.caml/browse_thread/th= read/f2acb593da91553c?hl=3Dfr&ie=3DUTF-8&q=3Dtype+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.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001636499007ce371b0460e9912f--