<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/01/eb1bb346ea9ac86f67b1c2011a41bdc8"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T13:25:52"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature"
  prev="2009/01/bdd60304d962e4e9ac5f3fc4516fce06"
  next="2009/01/13994d2261e2703a410b2818687311b2"
  prev-in-thread="2009/01/da6cc2637b564bfd93a0b72007d53fe0"
  next-in-thread="2009/01/3faf1d84d33d7d63e5f417f0853743b6"
  prev-thread="2009/01/6cfb5e559cd4bf982c4960d25352bc27"
  next-thread="2009/01/bdd60304d962e4e9ac5f3fc4516fce06"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Making a polymorphic type non-polymorphic to comply with original signature ">
<msg 
  url="2009/01/5086d82bd654331abd6d66fbfc5877f2"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T10:59:50"
  subject="Making a polymorphic type non-polymorphic to comply with original signature ">
<msg 
  url="2009/01/03af28a51b1f263e4bce45395c2a24ee"
  from="Daniel_Bünzli &lt;daniel.buenzli@e...&gt;"
  author="Daniel_Bünzli"
  date="2009-01-20T11:25:04"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
<msg 
  url="2009/01/45ebef4fa64ce8ca6d0ab81460203417"
  from="David Teller &lt;David.Teller@u...&gt;"
  author="David Teller"
  date="2009-01-20T11:37:28"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
<msg 
  url="2009/01/8291b0da375a697d829347a7a18148e7"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T11:46:45"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to	comply with original signature">
<msg 
  url="2009/01/da6cc2637b564bfd93a0b72007d53fe0"
  from="Thomas Gazagnaire &lt;ocaml@g...&gt;"
  author="Thomas Gazagnaire"
  date="2009-01-20T12:58:33"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply  with original signature">
<msg 
  url="2009/01/eb1bb346ea9ac86f67b1c2011a41bdc8"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T13:25:52"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/01/3faf1d84d33d7d63e5f417f0853743b6"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T11:43:13"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
</msg>
</msg>
<msg 
  url="2009/01/13994d2261e2703a410b2818687311b2"
  from="Martin Jambon &lt;martin.jambon@e...&gt;"
  author="Martin Jambon"
  date="2009-01-20T15:02:35"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
<msg 
  url="2009/01/bec8514bf8ec8e4b7403d82c8845ffa0"
  from="Hugo Ferreira &lt;hmf@i...&gt;"
  author="Hugo Ferreira"
  date="2009-01-20T17:05:16"
  subject="Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature">
</msg>
</msg>
</msg>
</thread>

<contents>
Thomas Gazagnaire wrote:
&gt; Or you can also functorize your own piece of code :
&gt; 
&gt; module Make (A : sig type t end) =
&gt; struct
&gt; 
&gt;     module rec H :
&gt;     sig
&gt;         type 'a node =
&gt;             | Node of 'a node J.t
&gt;             | Leaf of 'a
&gt;                  
&gt;         type t = A.t node
&gt;         val equal : t -&gt; t -&gt; bool
&gt;         val hash : t -&gt; int
&gt;     end =
&gt;     struct
&gt;         type 'a node =
&gt;             | Node of 'a node J.t
&gt;             | Leaf of 'a
&gt;                  
&gt;         type t = A.t node
&gt;         let equal = (==)
&gt;         let hash = Hashtbl.hash
&gt;     end
&gt;        
&gt;     and J : Hashtbl.S with type key = A.t H.node = Hashtbl.Make( H )
&gt;    
&gt; end
&gt;

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 = &lt;abstr&gt;

# let r = H.Node(jls) ;;
val r : '_a N.H.node = N.H.Node &lt;abstr&gt;

# let _ = J.add jls r r ;;
- : unit = ()

# let x = J.find jls r ;;
val x : int N.H.node = N.H.Node &lt;abstr&gt;

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


&gt; 2009/1/20 Hugo Ferreira &lt;hmf@inescporto.pt &lt;mailto:hmf@inescporto.pt&gt;&gt;
&gt; 
&gt;     David Teller wrote:
&gt; 
&gt;         It's probably feasible without copy &amp; paste by building a
&gt;         functor on top
&gt;         of the defunctorized hashtable in Batteries. Or by just using the
&gt;         defunctorized hashtable of Batteries directly, although it's not
&gt;         as safe
&gt;         as the functorized version, due to the absence of existential types.
&gt; 
&gt; 
&gt;     If I understand you correctly I would have to redefine equivalents for:
&gt;     - HashedType
&gt;     - S
&gt;     - Make(H: HashedType)
&gt; 
&gt;     Basically copy &amp; paste these and change the type.
&gt;     Doable although not to my liking.
&gt; 
&gt;     TIA,
&gt;     Hugo F.
&gt; 
&gt; 
&gt; 
&gt;         Cheers,
&gt;          David
&gt; 
&gt;         On Tue, 2009-01-20 at 12:24 +0100, Daniel Bünzli wrote:
&gt; 
&gt;             Le 20 janv. 09 à 11:59, Hugo Ferreira a écrit :
&gt; 
&gt;                 Is it possible to make H comply with Hashtbl.HashedType
&gt;                 i.e: make
&gt;                 J.Key = 'a H.node ?
&gt; 
&gt;             This issue is well known (e.g. see here [1]). Your are
&gt;             running into  limitations of the standard library. The only
&gt;             unsatisfying answer is  to copy the code from the standard
&gt;             library and add the parameter  yourself.
&gt; 
&gt;             Best,
&gt; 
&gt;             Daniel
&gt; 
&gt;             [1]
&gt;             http://groups.google.com/group/fa.caml/browse_thread/thread/f2acb593da91553c?hl=fr&amp;ie=UTF-8&amp;q=type+var+in+functor+fa.caml
&gt;             &lt;http://groups.google.com/group/fa.caml/browse_thread/thread/f2acb593da91553c?hl=fr&amp;ie=UTF-8&amp;q=type+var+in+functor+fa.caml&gt;
&gt; 
&gt;             ____________________________________________ugs
&gt; 
&gt; 
&gt;     _______________________________________________
&gt;     Caml-list mailing list. Subscription management:
&gt;     http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
&gt;     Archives: http://caml.inria.fr
&gt;     Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
&gt;     Bug reports: http://caml.inria.fr/bin/caml-bugs
&gt; 
&gt; 

</contents>

</message>

