From: Hugo Ferreira <hmf@inescporto.pt>
To: Thomas Gazagnaire <ocaml@gazagnaire.com>
Cc: David Teller <David.Teller@univ-orleans.fr>,
OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Making a polymorphic type non-polymorphic to comply with original signature
Date: Tue, 20 Jan 2009 13:25:45 +0000 [thread overview]
Message-ID: <4975D0D9.4060207@inescporto.pt> (raw)
In-Reply-To: <9722eaea0901200456v6b7b4b3doa11c8b1ea4dfee98@mail.gmail.com>
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 = <abstr>
# let r = H.Node(jls) ;;
val r : '_a N.H.node = N.H.Node <abstr>
# let _ = J.add jls r r ;;
- : unit = ()
# let x = J.find jls r ;;
val x : int N.H.node = N.H.Node <abstr>
# 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 <hmf@inescporto.pt <mailto:hmf@inescporto.pt>>
>
> 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
> <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
>
>
next prev parent reply other threads:[~2009-01-20 13:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-20 10:59 Hugo Ferreira
2009-01-20 11:24 ` [Caml-list] " Daniel Bünzli
2009-01-20 11:37 ` David Teller
2009-01-20 11:46 ` Hugo Ferreira
2009-01-20 12:56 ` Thomas Gazagnaire
2009-01-20 13:25 ` Hugo Ferreira [this message]
2009-01-20 11:43 ` Hugo Ferreira
2009-01-20 15:01 ` Martin Jambon
2009-01-20 17:05 ` Hugo Ferreira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4975D0D9.4060207@inescporto.pt \
--to=hmf@inescporto.pt \
--cc=David.Teller@univ-orleans.fr \
--cc=caml-list@yquem.inria.fr \
--cc=ocaml@gazagnaire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox