From: Virgile Prevosto <virgile.prevosto@m4x.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Open class types
Date: Tue, 1 Jul 2008 17:14:37 +0200 [thread overview]
Message-ID: <20080701171437.0cddf254@is005115> (raw)
In-Reply-To: <486A36DE.4040605@stork.ru>
Hello,
Le mar 01 jui 2008 17:53:34 CEST,
SerP <serp@stork.ru> a écrit :
> class type session_t =
> object
> method id:int;
> method location: #location_t;
> end;
>
...
>
> Error: This expression has type session = < id : int; location :
> location > but is here used with type
> #session_t as 'a = < id : int; location : 'b.
> #location_t; .. >
My guess is that session_t is a bit too polymorphic: location is
a polymorphic method (indicated by the 'b. in the error message). Thus,
a class implementing session_t should have a location method able to
return any subtype of location_t, which might be a bit complicated to
say the least. A more sensible class type would require that the
location method returns a subtype of location_t, which may differ from
one implementation to the other, but is fixed for a given
implementation. By the way, this matches more or less your second
solution.
At the class/class type level, this can be done by adding a type
parameter to the class type and using a constraint as shown below
(warning, this is the regular ocaml syntax, not the revised one):
class type ['a]session_t =
object
method id:int
method location: 'a
constraint 'a = #location_t
end
let check_session (session:'a #session_t) = begin
print_int session#id;
print_int session#location#a;
print_string session#location#b;
end
--
E tutto per oggi, a la prossima volta.
Virgile
prev parent reply other threads:[~2008-07-01 15:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-01 13:53 SerP
2008-07-01 15:02 ` [Caml-list] " Tiphaine Turpin
2008-07-01 15:14 ` Virgile Prevosto [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=20080701171437.0cddf254@is005115 \
--to=virgile.prevosto@m4x.org \
--cc=caml-list@yquem.inria.fr \
/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