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
[Caml-list] Recursive classes are impossible?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-24 (13:53)
From: Alessandro Baretta <alex@b...>
Subject: [Caml-list] Recursive classes are impossible?
 > Due to the typing system it is more or less impossible to
 > derive recursive classes in O'Caml. To get around this, it
 > is common practice to put the modifiable or extensible
 > part of recursive objects into parallel objects.

Hmmm... Now I am no object specialist, but this sounds a 
little weird to me. Now, let's see, doesn't the following 
code show that recursive classes are indeed possible in 
O'Caml? Or have I completely misunderstood what is meant by 
recursive object?

class ['a] broccoli =
	object (s)
	val mutable portion = None;
	method set (x:'a option) = portion <- x

let broccolo = new broccoli in
	broccolo#set (Some new broccoli);;

let broccolo = new broccoli in
	broccolo#set (Some broccolo);;

Sorry for mentioning broccoli, but it seemed appropriate 
given the recursive nature of their geometry.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: