Version française
Home     About     Download     Resources     Contact us    
Browse thread
type and class definition : recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: boos@g...
Subject: Re: type and class definition : recursion

pbrisset@eis.enac.dgac.fr writes:
 > I would like to define a class and a type with a mutual recursion between
 > them. Something like
 > 
 > 	type t = A
 > 	       | B of c
 > 	and class c (x:t) =
 >           val mutable value = x
 > 	end
 > 
 > Is it possible with O'caml ?
 > 
 > --------------

Yes :

#type 'a t = A | B of 'a;;
type 'a t = A | B of 'a
#class c (x : 'a t) : 'a = val mutable value = x end;;
class c ('a t) : 'a =
  val mutable value : 'a t
end
#let foo = new c A;;
val foo : c = <obj>
#let bar = new c (B foo);;
val bar : c = <obj>
#

-- Christian