Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Recursive classes and subtyping
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frederic Tronel <Frederic.Tronel@i...>
Subject: [Caml-list] Recursive classes and subtyping
Hello,

A new question about classes in ocaml:

Why is it that these classes definitions are not accepted by
the compiler :

class a =
  object
    val mutable al = ([] : a list)
    method get_al = al
    method set_al x = al <- x 
  end
and b =
object (this)
  inherit a as super
  val mutable c = new c
  method get_c = c
  method set_c x = c <- x
  initializer this#set_al [(c :> a)] 
end
and c =
object 
  inherit a
  val mutable titi = ""
  method get_titi = titi
  method set_titi x = titi <- x
end

while these ones can be compiled:

class a =
  object
    val mutable al = ([] : a list)
    method get_al = al
    method set_al x = al <- x 
  end
class c =
object 
  inherit a
  val mutable titi = ""
  method get_titi = titi
  method set_titi x = titi <- x
end
class b =
object (this)
  inherit a as super
  val mutable c = new c
  method get_c = c
  method set_c x = c <- x
  initializer this#set_al [(c :> a)] 
end

Where is the fundamental difference ????

Best regards,

Frederic
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr