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 SAA02643 for caml-redistribution; Thu, 13 Nov 1997 18:18:40 +0100 (MET) 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 RAA09400 for ; Wed, 12 Nov 1997 17:29:41 +0100 (MET) Received: from enst.enst.fr (enst.enst.fr [137.194.2.16]) by nez-perce.inria.fr (8.8.7/8.8.5) with ESMTP id RAA02092 for ; Wed, 12 Nov 1997 17:29:39 +0100 (MET) Received: from liszt.enst.fr (liszt.enst.fr [137.194.4.32]) by enst.enst.fr (8.8.4/8.8.4) with SMTP id RAA15966; Wed, 12 Nov 1997 17:29:36 +0100 (MET) Received: from cal.enst.fr (cal-ppp19.ppp.enst.fr) by liszt.enst.fr (MX V4.2 AXP) with SMTP; Wed, 12 Nov 1997 17:29:40 MET Message-ID: <3469D664.905BB6EF@cal.enst.fr> Date: Wed, 12 Nov 1997 17:16:36 +0100 From: Michel Quercia X-Mailer: Mozilla 4.03 [en] (X11; I; Linux 2.0.29 i586) MIME-Version: 1.0 To: Simon Helsen , Caml Mailing-list Subject: Re: recursive datatypes References: Sender: weis Simon Helsen wrote: > Why does Caml type-check the following program? It wouldn't in Standard ML > and I don't see the use for it, as it may lead to infinite programs... > > (I don't have a french keyboard) > > Pourquoi est le programme ci-desous bon type ? C'est ne pas le > cas en Standard ML et je ne comprend pas l'usage pour ca parce que le > programme peut eventuellement cours a l'infini... > > type 'a tree = Tree of 'a > > let f x = Tree (f x) > Hi, Your code does'nt typecheck with both camllight 0.73 and ocaml 1.05. With ocaml1.05, the following code does typecheck : ---------------------------------------- Objective Caml version 1.05 # type 'a tree = Tree of 'a;; type 'a tree = | Tree of 'a # let f x = Tree (f x);; Unbound value f # let rec f x = Tree (f x);; val f : 'a -> ('b tree as 'b) = # f(3);; Out of memory during evaluation # --------------------------------------- I can't explain the "('b tree as 'b)", but why your post is entitled "recursive datatypes" ? Did you mean : type 'a tree = Tree of 'a tree ? This type declaration is accepted and it is possible to build 'a tree objects : -------------------------------------- # type 'a tree = Tree of 'a tree;; type 'a tree = | Tree of 'a tree # #print_depth 5;; # let rec x = Tree(y) and y = Tree(x);; val x : 'a tree = Tree (Tree (Tree (Tree (Tree (Tree ...))))) val y : 'a tree = Tree (Tree (Tree (Tree (Tree (Tree ...))))) ------------------------------------- -- Michel Quercia Lycee Carnot 16 bd Thiers 21000 Dijon mailto:quercia@cal.enst.fr