caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] implicit subtyping in method argument and parameterized class
@ 2002-09-04 23:18 Pixel
  2002-09-05  1:02 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Pixel @ 2002-09-04 23:18 UTC (permalink / raw)
  To: caml-list

[-- 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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-05  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-04 23:18 [Caml-list] implicit subtyping in method argument and parameterized class Pixel
2002-09-05  1:02 ` Jacques Garrigue

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).