Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Typing problem with polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Typing problem with polymorphic variants
From: David Brown <caml-list@davidb.org>

> I would apply the same question to the object system: why can a
> signature not hide methods of a class.
> 
> Does making the signature more restrictive somehow hurt the type system?
> 
> e.g.:
> 
>   class foo : object method baz : int end =
>     object
>       method baz = 5
>       method bar = 2
>     end
> 
> gives:
> 
>   The class type object method bar : int method baz : int end
>   is not matched by the class type object method baz : int end
>   The public method bar cannot be hidden


Just consider now a variant on your example:

  class foo : object method baz : int end =
    object (self)
      method baz = self#bar + 3
      method bar = 2
    end

  class bar = object
    inherit foo
    method bar = "hello"
  end

If you can forget the method bar, the class bar becomes typable.
However (new bar)#baz lead to computing ["hello" + 3] which is
unsound.

You can try to change the problem in many ways, but the conclusion is
that there is no way to allow the hiding of a public method without a
notion of generative types for objects or views. There is a paper by
Jerome Vouillon on the subject
  http://www.pps.jussieu.fr/~vouillon/publi.html
  Combining subsumption and binary methods: An object calculus with views.

Jacques Garrigue

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