Browse thread
Problem with recursive class and non-class types
-
Goswin von Brederlow
-
Jacques Garrigue
- Goswin von Brederlow
-
Jacques Garrigue
[
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: | Goswin von Brederlow <goswin-v-b@w...> |
| Subject: | Re: [Caml-list] Problem with recursive class and non-class types |
Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> writes:
> From: Goswin von Brederlow <goswin-v-b@web.de>
>> I want to define the two types below:
>>
>> type foo = { bar : bar; }
>> class bar = object val mutable foo : foo list = [] end
>>
>> Is there another way of doing this other than:
>>
>> # type 'a foo = { bar : 'a; }
>> class bar = object val mutable foo : #bar foo list = [] end;;
>> type 'a foo = { bar : 'a; }
>> class bar : object val mutable foo : #bar foo list end
>
> The alternative is to use a recursive module, but this is actually
> more verbose.
>
> module rec M : sig
> type foo = { bar : M.bar; }
> class bar : object val mutable foo : foo list end
> end = struct
> type foo = { bar : M.bar; }
> class bar = object val mutable foo : foo list = [] end
> end
>
> You can avoid a bit of the verboseness by splitting types and values,
> since recursive modules built only from types require no duplication.
>
> module rec M : sig
> type foo = { bar : M.bar; }
> class type bar = object val mutable foo : foo list end
> end = M
>
> class bar : M.bar = object val mutable foo : M.foo list = [] end
>
> You still need to provide an explicit interface for bar.
>
> Hope this helps,
>
> Jacques Garrigue
Thanks, it does. It isn't nice but it does solve the problem. Now I have
to decide what I live with. 'a foo uglyness or module rec uglyness.
It is too bad a simple
type foo = ...
and class bar = ...
doesn't work.
MfG
Goswin