From: Goswin von Brederlow <goswin-v-b@web.de>
To: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
Cc: goswin-v-b@web.de, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem with recursive class and non-class types
Date: Fri, 21 May 2010 20:01:17 +0200 [thread overview]
Message-ID: <87iq6hrv6a.fsf@frosties.localdomain> (raw)
In-Reply-To: <20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp> (Jacques Garrigue's message of "Thu, 20 May 2010 16:39:02 +0900 (JST)")
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
prev parent reply other threads:[~2010-05-21 18:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-20 5:12 Goswin von Brederlow
2010-05-20 7:39 ` [Caml-list] " Jacques Garrigue
2010-05-21 18:01 ` Goswin von Brederlow [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87iq6hrv6a.fsf@frosties.localdomain \
--to=goswin-v-b@web.de \
--cc=caml-list@yquem.inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox