From: Pixel <pixel@mandrakesoft.com>
To: caml-list@inria.fr
Subject: [Caml-list] implicit subtyping in method argument and parameterized class
Date: 05 Sep 2002 01:18:19 +0200 [thread overview]
Message-ID: <lyofbdjqdg.fsf@leia.mandrakesoft.com.> (raw)
[-- Attachment #1: Type: text/plain, Size: 532 bytes --]
With ocaml 3.06 we are now able to replace
method with_foo : foo -> unit = ...
with
method with_foo : 'a. (#foo as 'a) -> unit = ...
and get implicit subtyping when calling with_foo.
But I can't make it work when "foo" is a parametric variable:
method with_foo : 'foo -> unit = ...
works whereas
method with_foo : 'a. (#'foo as 'a) -> unit = ...
gives "Syntax error", and
method with_foo : 'a. ('foo as 'a) -> unit = ...
gives "This type has no row variable"
Is there a solution?
thanks.
Full example:
[-- Attachment #2: implicit-method-argument-subtyping.ml --]
[-- Type: text/plain, Size: 1833 bytes --]
module Before_ocaml_3_06 = struct
class foo = object method foo = () end
class foo' = object inherit foo method foo' = () end
class on_any_foo =
object
method with_foo : foo -> unit = fun foo -> foo#foo
end
class ['foo] on_that_foo =
object
method with_foo : 'foo -> unit = fun foo -> foo#foo
end
class on_foo = [foo ] on_that_foo
class on_foo' = [foo'] on_that_foo
let _ =
let foo = new foo in
let foo' = new foo' in
let on_any_foo = new on_any_foo in
let on_foo = new on_foo in
let on_foo' = new on_foo' in
on_any_foo #with_foo (foo' :> foo) ; (* explicit subtyping *)
on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *)
on_foo' #with_foo foo' ;
()
end
module Ocaml_3_06 = struct
class foo = object method foo = () end
class foo' = object inherit foo method foo' = () end
class on_any_foo =
object
method with_foo : 'a. (#foo as 'a) -> unit = fun foo -> foo#foo
end
class ['foo] on_that_foo =
object
method with_foo : 'foo -> unit = fun foo -> foo#foo
(* could be something like: *)
(* method with_foo : 'a. (#'foo as 'a) -> unit = fun foo -> foo#foo *)
(* and calling: [foo] on_that_foo *)
(* method with_foo : 'a. ('foo as 'a) -> unit = fun foo -> foo#foo *)
(* and calling: [#foo] on_that_foo *)
end
class on_foo = [foo ] on_that_foo
class on_foo' = [foo'] on_that_foo
let _ =
let foo = new foo in
let foo' = new foo' in
let on_any_foo = new on_any_foo in
let on_foo = new on_foo in
let on_foo' = new on_foo' in
on_any_foo #with_foo foo' ; (* implicit subtyping *)
on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *)
on_foo' #with_foo foo' ;
()
end
[-- Attachment #3: Type: text/plain, Size: 76 bytes --]
--
programming languages addict http://merd.net/pixel/language-study/
next reply other threads:[~2002-09-04 23:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-04 23:18 Pixel [this message]
2002-09-05 1:02 ` Jacques Garrigue
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=lyofbdjqdg.fsf@leia.mandrakesoft.com. \
--to=pixel@mandrakesoft.com \
--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;
as well as URLs for NNTP newsgroup(s).