English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] recursive type declaration
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-01 (08:26)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] recursive type declaration
From: dengping zhu <zhudp@cs.bu.edu>
> Now I want to define a type and a class, both of which are recursive
> defined as follows:
> ----------------
> type ty1 =
>    | Int of int
>    | String of string
>    | Class of typeClass
> class virtual typeClass =
>    object
>       method virtual typeCon : ty1
>    end;;
> -----------------
> However, it does not work. 
> I can use another way to solve it by define ty1 as 'a ty1. Besides this
> way, is there any method to solve it? What's more, what's the common way
> to define such types?

I believe this is a FAQ.

Just parameterize one one of the two.
For instance:

type 'tc ty1 =
   | Int of int
   | String of string
   | Class of 'tc

class virtual typeClass =
      method virtual typeCon : typeClass ty1

Arguably, this is a misfeature of the language that you cannot define
the two together, but then recursive class definitions and type
definitions do not handle constraints in the same way, so this would
be hard to mix them properly.

Jacques Garrigue
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners