Jacques Garrigue <garri
...@math.nagoya-u.ac.jp> writes:
> From: Goswin von Brederlow <goswin-
...@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.
type foo = ...
and class bar = ...
doesn't work.