From: nadji@noos.fr
To: caml-list@inria.fr
Subject: [Caml-list] polymorphic methods
Date: Mon, 15 Jul 2002 01:16:53 +0200 [thread overview]
Message-ID: <3D320665.AC5539CD@noos.fr> (raw)
Hello,
While playing with the current cvs version of ocaml (3.04+15),
several questions came to me concerning the semantics of
polymorphic methods. For example :
# class c = object
method ~m: 'a . unit -> 'a -> 'a = fun _ x -> x
end;;
class c : object method m : unit -> 'a -> 'a end
# let f = (new c)#m ();;
val f : '_a -> '_a = <fun>
Shouldn't the type of f be : 'a -> 'a ?
(Would it be sound/implementable/easy to add ?)
Second question:
# class ['a] d = object
method m: 'a -> 'a = fun x -> x
end;;
class ['a] d : object method m : 'a -> 'a end
# class subd = object
method ~m: 'a. 'a -> 'a = fun x -> x
end;;
class subd : object method m : 'a -> 'a end
# let v = (new subd :> 'a d);;
Characters 9-17:
let v = (new subd :> 'a d);;
^^^^^^^^
This expression cannot be coerced to type 'a d = < m : 'a -> 'a >;
it has type subd = < m : 'b. 'b -> 'b > but is here used with type 'a d
Or even the easier :
# class d' = object
method m x = x + 0
end;;
class d' : object method m : int -> int end
# let v' = (new subd :> d');;
Characters 10-18:
let v' = (new subd :> d');;
^^^^^^^^
This expression cannot be coerced to type d' = < m : int -> int >;
it has type subd = < m : 'a. 'a -> 'a > but is here used with type d'
But the type ('b. 'b -> 'b) is more general than ('a -> 'a)
or (int -> int), no ?
Can someone give me some hints why I can't coerce subd ?
Btw, thanks for the upcoming release, it seems _really_ excellent !
Nadji
-------------------
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
next reply other threads:[~2002-07-14 23:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-14 23:16 nadji [this message]
2002-07-15 1:05 ` Jacques Garrigue
2002-07-15 2:08 ` Brian Smith
2002-07-15 16:24 ` nadji
-- strict thread matches above, loose matches on Subject: below --
2015-12-18 9:18 Christoph Höger
2015-12-18 10:07 ` Leo White
2003-03-12 23:07 Damien
2003-03-13 0:56 ` brogoff
2003-03-13 1:56 ` Jacques Garrigue
2003-03-13 9:04 ` Damien
2003-03-13 9:27 ` Jacques Garrigue
2003-03-13 14:49 ` Damien
2003-03-13 9:41 ` Olivier Andrieu
2002-08-23 15:46 [Caml-list] Polymorphic methods Frederic Tronel
2002-08-23 17:32 ` Fred Smith
2002-08-23 18:21 ` Remi VANICAT
2001-11-19 15:29 Alain Frisch
2001-11-20 0:29 ` Jacques Garrigue
2001-11-20 9:33 ` Alain Frisch
2001-11-20 20:55 ` Xavier Leroy
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=3D320665.AC5539CD@noos.fr \
--to=nadji@noos.fr \
--cc=caml-list@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