From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA27672; Sun, 2 Jun 2002 11:08:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA28033 for ; Sun, 2 Jun 2002 11:08:10 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g52989n27673 for ; Sun, 2 Jun 2002 11:08:09 +0200 (MET DST) Received: from force.stwing.upenn.edu (daemon@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.11.6/8.11.6) with ESMTP id g52986X09891 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Sun, 2 Jun 2002 05:08:07 -0400 (EDT) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.11.6/8.11.6) id g52986D19635 for caml-list@inria.fr; Sun, 2 Jun 2002 05:08:06 -0400 (EDT) Date: Sun, 2 Jun 2002 05:08:06 -0400 From: William Lovas To: caml-list@inria.fr Subject: Re: [Caml-list] recursive type declaration Message-ID: <20020602090805.GA19236@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <20020601172611W.garrigue@kurims.kyoto-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020601172611W.garrigue@kurims.kyoto-u.ac.jp> User-Agent: Mutt/1.3.25i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Jun 01, 2002 at 05:26:11PM +0900, Jacques Garrigue wrote: > From: dengping zhu > > 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 = > object > method virtual typeCon : typeClass ty1 > end;; Incidentally, if you really wanted an alternative, you could explicitly specify the methods you need in ty1's definition, since (i think) class types are just an abbreviation for objects containing all the necessary methods. i.e.: type ty1 = | Int of int | String of string | Class of < typeCon : ty1 > class virtual typeClass = object method virtual typeCon : ty1 end This is inferior to parametrization in at least two ways: 1. It most likely fails to capture the intended generalization, making the whole thing more error prone, and 2. With a larger example, it could be quite cumbersome (related to 1., in a way). It's a possibility, but it seems to have a pretty high ugly potential... William ------------------- 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