From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA05274 for caml-red; Mon, 5 Feb 2001 17:55:13 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA18415 for ; Sun, 4 Feb 2001 23:23:50 +0100 (MET) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f14MNn902952 for ; Sun, 4 Feb 2001 23:23:49 +0100 (MET) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id OAA07419; Sun, 4 Feb 2001 14:23:41 -0800 (PST) Date: Sun, 4 Feb 2001 14:23:41 -0800 (PST) From: Brian Rogoff To: Stephan Tolksdorf cc: caml-list@inria.fr Subject: Re: Unbound type constructor In-Reply-To: <9114178788.20010203181656@gmx.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr On Sat, 3 Feb 2001, Stephan Tolksdorf wrote: > I'm learning OCaml... > > The following code snippet fails due to an "unbound type constructor" > error. How could I achieve the intended result in OCaml? > > type combination = T1 of int | T2 of test | T3 of test * test > > class test = > object > method virtual get : combination > end The problem is that cuurrently you can't have classes and types in a mutually recursive declaration, and you can't even have "class types" in such declarations, but you can put "object types" (see the OCaml manual under Type Expressions) in and then use object types to constrain the return value of method get. # type combination = T1 of int | T2 of test | T3 of test * test and test = ;; type combination = T1 of int | T2 of test | T3 of test * test type test = < get : combination > # class my_test = object(self) method get = T2 (self:>test) end;; class my_test : object method get : combination end There are probably other ways to do what you want too. -- Brian