From: Olivier Andrieu <andrieu@ijm.jussieu.fr>
To: pan deng <onlyclimb@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] how to open types
Date: Mon, 4 Nov 2002 13:41:37 +0100 [thread overview]
Message-ID: <15814.27393.880341.225808@akasha.ijm.jussieu.fr> (raw)
In-Reply-To: <20021104082539.18529.qmail@web11103.mail.yahoo.com>
pan deng [Monday 4 November 2002] :
>
> I want to use hashtable on my objects which all has a
> method get_string:string.
> but i can only write the code like these:
>
> module SeqHashType =
> struct
> type t= <get_string:string >
> let equal s1 s2 = (String.uppercase s1#get_string
> =String.uppercase s2#get_string )
> let hash s = Strex.hash s#get_string
> end
> module SeqHashtbl = Hashtbl.Make (SeqHashType)
>
> surely it is not what i want . i have tried
> type t= <get_string:string ; ..>
>
> but i can not complie it , the complier says Unbound
> ..
Yes, "open" object type have an implicit type parameter that you have
to specify in the definition :
type 'a t = 'a constraint <get_string: string; ..>
> then how to open the type <get_string:string> in the
> module SeqHashType ?
> or it can not be opened at this situation ?
You cannot because in the module signature Hashtbl.HashedType, type t
isn't polymorph.
I guess the solution would be to use
type t = <get_string:string>
and to coerce your objects to this
(o :> SeqHashType.t)
--
Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2002-11-04 12:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-04 8:25 pan deng
2002-11-04 12:41 ` Olivier Andrieu [this message]
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=15814.27393.880341.225808@akasha.ijm.jussieu.fr \
--to=andrieu@ijm.jussieu.fr \
--cc=caml-list@inria.fr \
--cc=onlyclimb@yahoo.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;
as well as URLs for NNTP newsgroup(s).