Re: Tree of a certain class:

From: Jerome Vouillon (Jerome.Vouillon@inria.fr)
Date: Fri Sep 24 1999 - 14:35:24 MET DST


Date: Fri, 24 Sep 1999 14:35:24 +0200
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: Peter Schrammel <peter.schrammel@unibw-muenchen.de>,
Subject: Re: Tree of a certain class:
In-Reply-To: <37EB3338.4E226250@unibw-muenchen.de>; from Peter Schrammel on Fri, Sep 24, 1999 at 10:15:52AM +0200

On Fri, Sep 24, 1999 at 10:15:52AM +0200, Peter Schrammel wrote:
> I wrote a Program:
> type 'i tree =
> Empty
> | Item of 'i
> | Section of 'i * 'i
>
> class ['i] ctree =
> object (self : 'a)
> val mutable content : 'i tree = Empty
>
> method get = content
>
> end
>
> class debug =
> object
> method debug = ()
> end
>
> class dtree =
> object
> inherit [#debug] ctree
> end
>
> But the compiler gives me the error:
>
> Some type variables are unbound in this type:
> class dtree :
> object val mutable content : (#debug as 'a) tree method get : 'a
> tree end
> The method get has type #debug tree where .. is unbound
> make: *** [test.cmo] Error 2
>
> How can make trees of a certain (sub)class ? (I hope there's a simple
> solution)

Depending on your needs, you can either write
    class dtree =
      object
        inherit [debug] ctree
    end
or
    class ['a] dtree =
      object
        constraint 'a = #debug
        inherit ['a] ctree
    end
In the first case, the type of the contained object is fixed. In the
second case it is only required to be an instance of type
   #debug = < debug : unit; .. >
So, if you write a subclass debug2 of class debug, an object of type
"debug2 dtree" will contain objects of type "debug2".

Regards,

-- Jérôme



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:25 MET