From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: goswin-v-b@web.de
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem with recursive class and non-class types
Date: Thu, 20 May 2010 16:39:02 +0900 (JST) [thread overview]
Message-ID: <20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <87mxvvma1r.fsf@frosties.localdomain>
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
next prev parent reply other threads:[~2010-05-20 7:39 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 ` Jacques Garrigue [this message]
2010-05-21 18:01 ` [Caml-list] " Goswin von Brederlow
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=20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@yquem.inria.fr \
--cc=goswin-v-b@web.de \
/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