caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Recursive class+type definitions
Date: Mon, 16 Jul 2007 03:00:52 +0100	[thread overview]
Message-ID: <200707160300.52686.jon@ffconsultancy.com> (raw)
In-Reply-To: <11E0700C-4331-42AB-88F1-E6BD21D72F78@rice.edu>

On Monday 16 July 2007 02:29:47 Raj B wrote:
> Hi all
>
> Can we have mutually recursive definitions mixing types and classes?
> For example, I want to define
> a class called mypoint, which contains another data structure (say, a
> custom list) of mypoints.
>
> 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?

Good question. No idea. But you can do this:

class virtual ['a] mypoint = object
  method virtual getx : float
  method virtual getlist : 'a
end;;

type mypointlist = Empty | Cons of (mypointlist mypoint * mypointlist);;

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e


  reply	other threads:[~2007-07-16  2:06 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 ` Jon Harrop [this message]
2007-07-16  2:27 ` [Caml-list] " Chris King
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=200707160300.52686.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).