From: "Chris King" <colanderman@gmail.com>
To: "Raj B" <rajb@rice.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Recursive class+type definitions
Date: Sun, 15 Jul 2007 22:27:53 -0400 [thread overview]
Message-ID: <875c7e070707151927t529c3e2anb2dc9a5c5bf634fe@mail.gmail.com> (raw)
In-Reply-To: <11E0700C-4331-42AB-88F1-E6BD21D72F78@rice.edu>
On 7/15/07, Raj B <rajb@rice.edu> wrote:
> class virtual mypoint =
> object
> method virtual getx : float
> method virtual getlist : mypointlist
> end
>
> type mypointlist = Empty | Cons of (mypoint * mypointlist)
>
> What is the best way to achieve this kind of mutual recursion?
I'd write something like:
type mypointlist = Empty | Cons of (< getx: float; getlist:
mypointlist > * mypointlist)
class virtual ...
or:
type mypointlist = Empty | Cons of (mypoint * mypointlist)
and mypoint = < getx: float; getlist: mypointlist >
in the case that having an inheritable virtual class isn't important to you.
You can get the exact behavior you want using a pair of recursive
modules (see the "Language Extensions" section of the manual), one for
each of mypoint and mypointlist, but it's a lot more verbose (since
recursive modules require you to explicity give their signatures).
HTH,
Chris
next prev parent reply other threads:[~2007-07-16 2:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-16 1:29 Raj B
2007-07-16 2:00 ` [Caml-list] " Jon Harrop
2007-07-16 2:27 ` Chris King [this message]
2007-07-16 9:00 ` Jacques GARRIGUE
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=875c7e070707151927t529c3e2anb2dc9a5c5bf634fe@mail.gmail.com \
--to=colanderman@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=rajb@rice.edu \
/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