caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: "Sébastien Hinderer" <Sebastien.Hinderer@ens-lyon.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] mutually dependent class and type
Date: Fri, 26 Sep 2008 01:41:29 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0809260112050.10536@martin.ec.wink.com> (raw)
In-Reply-To: <20080925222439.GA7968@galois>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1294 bytes --]

On Fri, 26 Sep 2008, Sébastien Hinderer wrote:

> Dear list,
>
> Is there a (clean) way to define simultaneously a class and a type that
> are mutually recursive ?

I don't think so, but you don't have to.

> Something like this :
> class element (c : content) =
> object
>  ...
> end and type content =
>  | Data of string
>  | Elements of element list;;
>
> This is of course not a valid OCaml definition, but is there a way to
> express it ?

With each class comes a type of the same name. Such type can also be 
defined independently from the notion of class. It is syntactically like 
a record with angle brackets:

type element =
     < content : content >

and content =
     Data of string
   | Elements of element list;;

class element_class (c : content) =
object
   method content = c
end


# new element_class (Elements [ new element_class (Data "abc") ]);;
- : element_class = <obj>


Martin

> Many thanks in advance for your help,
> Sébastien.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
http://mjambon.com/

  reply	other threads:[~2008-09-25 23:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-25 22:24 Sébastien Hinderer
2008-09-25 23:41 ` Martin Jambon [this message]
2008-09-26  6:40 ` [Caml-list] " Tim Rentsch
2008-10-05 13:31 ` Yann Régis-Gianas

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.LNX.4.64.0809260112050.10536@martin.ec.wink.com \
    --to=martin.jambon@ens-lyon.org \
    --cc=Sebastien.Hinderer@ens-lyon.org \
    --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).