Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Overriding with subtypes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-08-31 (12:15)
From: Gert Smolka <smolka@p...>
Subject: Overriding with subtypes
It should be ok to override a method of type t
with a method of a subtype of  t.  In fact,
that happens in

class c  = object(self) method a = self end
class c' = object(self) inherit c method a = self method b = 1 end

since c' is a proper subtype of c.  This is accepted by
Ocaml.  However,

class d  = object method a = new c end
class d' = object inherit d method a = new c' end

is rejected.  Why?  I would expect that this is a
limitation that is due to the type inferencer.

Gert Smolka