caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: John Max Skaller <skaller@ozemail.com.au>
Cc: Tom Hirschowitz <hirschow@mouton.inria.fr>, caml-list@inria.fr
Subject: Re: circular types?
Date: Wed, 25 Oct 2000 12:47:08 -0700 (PDT)	[thread overview]
Message-ID: <Pine.BSF.4.21.0010251230020.4675-100000@shell5.ba.best.com> (raw)
In-Reply-To: <39F6E831.621B85E3@ozemail.com.au>

On Thu, 26 Oct 2000, John Max Skaller wrote:
> Brian Rogoff wrote:
> > And if you can do that then allowing mutual recursion between
> > classes and types also should be allowed.
> 
> I think this can be done now. Here is the method: to have a type t
> and a class c mutually dependent, for example:
> 
> 	class type c = object x : t end
> 	and type  t = C c | Null
> 
> write
> 
> 	class type c' ['t] = object x : 't end
> 	type t = C t c' | Null
> 	class type c = t c'
> 
> and you have it. In other words, abstract out the types from
> the classes by making them type parameters, declare the types,
> using appropriately instantiated class types, and then name the
> required class instances.

Yes, it's the same trick that I pointed out for module/type recursions; as 
they say any problem can be solved by another level of indirection. I'd
like to be able to express this directly with an "and" of course.

Check your syntax too, it's really

class type ['a] c' = object method x : 'a end;;
type t = C of t c' | Null;;
class type c = object inherit [t] c' end;;

and note that this works with virtual classes as well as class types 

class virtual ['a] c' = object method virtual x : 'a end;;
type t = C of t c' | Null;;
class virtual c = object inherit [t] c' end;;
class foo a_t = object inherit c method x = a_t end;;
let f0 = new foo Null;;
let f1 = new foo (C f0);;

Before anyone complains about those horrid double semi-colons I point out
that those lines are all accepted by the top-level ;;-)

-- Brian




  reply	other threads:[~2000-10-25 20:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-23  7:43 Tom Hirschowitz
2000-10-23 15:35 ` Brian Rogoff
2000-10-25 14:03   ` John Max Skaller
2000-10-25 19:47     ` Brian Rogoff [this message]
2000-10-26  9:12     ` Hendrik Tews
2000-10-26 16:37       ` John Max Skaller
2000-10-24  8:37 ` Hendrik Tews
2000-10-25 14:31   ` John Max Skaller
2000-10-26  8:51     ` Hendrik Tews
  -- strict thread matches above, loose matches on Subject: below --
2000-10-24  8:48 Tom Hirschowitz
2000-10-26  8:39 ` Hendrik Tews
2000-10-26  9:11   ` Tom Hirschowitz
2000-10-20  2:35 Chris Hecker
2000-10-20 12:24 ` Pierre Weis
2000-10-20 21:34   ` Chris Hecker
2000-10-21  8:02     ` Pierre Weis
2000-10-21 18:37       ` Chris Hecker
2000-10-21 12:22     ` Vitaly Lugovsky
2000-10-21 18:29       ` Chris Hecker
2000-10-21 22:36     ` Brian Rogoff
2000-10-23 18:43     ` Anton Moscal

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=Pine.BSF.4.21.0010251230020.4675-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=hirschow@mouton.inria.fr \
    --cc=skaller@ozemail.com.au \
    /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).