Re: type and class definition : recursion

Christian Boos (boos@gr6.u-strasbg.fr)
Tue, 14 May 96 22:04:56 +0200

Date: Tue, 14 May 96 22:04:56 +0200
From: boos@gr6.u-strasbg.fr (Christian Boos)
Message-Id: <9605142004.AA03001@gr6.u-strasbg.fr>
To: pbrisset@eis.enac.dgac.fr
Subject: Re: type and class definition : recursion
In-Reply-To: <199605141211.OAA06278@concorde.inria.fr>

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