Browse thread
Re: What am I missing?
-
Pierre Weis
-
Peter Schrammel
- Sylvain BOULM'E
- Pierre Boulet
- Jerome Vouillon
-
Peter Schrammel
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jerome Vouillon <Jerome.Vouillon@i...> |
| Subject: | Re: Tree of a certain class: |
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