caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: pixel@mandrakesoft.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] implicit subtyping in method argument and parameterized class
Date: Thu, 05 Sep 2002 10:02:44 +0900	[thread overview]
Message-ID: <20020905100244U.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <lyofbdjqdg.fsf@leia.mandrakesoft.com.>

From: Pixel <pixel@mandrakesoft.com>
> 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.

Note that this implicit subtyping is essentially width-subtyping (the
object passed may have more methods), but not full subtyping (the
methods may not have subtypes).

> 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?

No.
Class parameters are just type variables. You can unify them, but no
more. ('foo as 'a) is equivalent to 'foo constraint 'a = 'foo.

Note also that since the scope of 'a is the whole method type, this
doesn't make sense from a typing point of view.
What might make sense is:
  class ['with_foo] on_that_foo with_foo =
    object
      method with_foo : 'with_foo = with_foo
    end
  let o = new on_that_foo (fun x -> x#foo : 'a. (#some_foo as 'a) -> unit)
But this would require first class polymorphic functions, which are
not yet in the language. And if you want to share the code in the
class, you would also need subtyping between explicitly polymorphic
types, which is not there either.

       Jacques
-------------------
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


      reply	other threads:[~2002-09-05  1:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-04 23:18 Pixel
2002-09-05  1:02 ` Jacques Garrigue [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=20020905100244U.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=pixel@mandrakesoft.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).