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 LAA09191 for caml-redistribution; Fri, 26 Nov 1999 11:00:04 +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 WAA23701 for ; Thu, 25 Nov 1999 22:27:22 +0100 (MET) Received: from beach.frankfurt.netsurf.de (beach.frankfurt.netsurf.de [194.64.181.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id WAA14971 for ; Thu, 25 Nov 1999 22:27:21 +0100 (MET) Received: from ice.darmstadt.netsurf.de (board-48.darmstadt.netsurf.de [194.163.86.176]) by beach.frankfurt.netsurf.de (8.8.5/8.8.5) with ESMTP id WAA15316 for ; Thu, 25 Nov 1999 22:27:18 +0100 (MET) Received: from localhost (localhost [[UNIX: localhost]]) by ice.darmstadt.netsurf.de (8.9.3/8.9.3) id WAA07258 for caml-list@inria.fr; Thu, 25 Nov 1999 22:26:46 +0100 From: Gerd Stolpmann Reply-To: Gerd.Stolpmann@darmstadt.netsurf.de Organization: privat To: caml-list@inria.fr Subject: Re: The option -rectypes Date: Thu, 25 Nov 1999 21:51:21 +0100 X-Mailer: KMail [version 1.0.21] Content-Type: text/plain References: <19991124215630.05496@pauillac.inria.fr> MIME-Version: 1.0 Message-Id: <99112522264600.07026@ice> Content-Transfer-Encoding: 8bit Sender: weis On Wed, 24 Nov 1999, Xavier Leroy wrote: >> - What is the effect of -rectypes? (I did not find a good explanation in the >> manual.) > >It relaxes the type-checking so that recursive types are accepted >everywhere. The "standard" behavior is that recursive types are >rejected if the recursion doesn't cross an object type, e.g. > > < m : 'a -> 'a> as 'a > >is accepted, but > > ('a -> 'a) as 'a > >is not. In my example, the recursion does only formally not cross an object type. If you expand 'a node extension as 'a, you get < clone : 'a; node : 'a node; 'a node -> unit > as 'a Perhaps this is the reason why Ocaml 2.02 accepts the type, and 2.03 does not; the order when type constructors are expanded might have changed. Note that Ocaml 2.03 still accepts 'a node #extension as 'a. (Perhaps the compiler interprets the hash mark as indicator that an "extension" is actually an object type?) >The reason for this restriction is that while recursive types >are a necessity for typing objects, they are a mixed blessing for >other kinds of types. Granted, they allow more programs to be >type-checked, but they also lead to programming mistakes not being >detected by the type-checker, instead the type-checker infers >nonsensical recursive types. For instance, conside the function > > let f x = x @ x > >and assume that by mistake I type > > let f x = x :: x > >instead. Without recursive types, I get a type error. With >unrestricted recrusive types, f is well-typed but with an essentially >unusable type > > ('a list) as 'a > >and attempts to use f later will fail with very strange type error >messages. We tried to put unrestricted recursive types in one of the >OCaml releases, and got many, many complains from users telling us >that this made the language much harder to use, especially for teaching. This means: It is impossible that an incorrectly typed program can at once be compiled only because I use an almost undocumented option. The main effect is that more correctly typed programs can be compiled, and the side effect is that the quality of error message decreases. I think that the restriction of recursive types is okay as long as abbreviated object types are handled permissively. Gerd -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: Gerd.Stolpmann@darmstadt.netsurf.de (privat) Germany ----------------------------------------------------------------------------