From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 40980BC8A for ; Sun, 30 Jan 2005 11:33:12 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0UAXB8x023865 for ; Sun, 30 Jan 2005 11:33:11 +0100 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 LAA13482 for ; Sun, 30 Jan 2005 11:33:11 +0100 (MET) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0UAX9v2009862; Sun, 30 Jan 2005 11:33:10 +0100 Received: by yquem.inria.fr (Postfix, from userid 18180) id A8B79BC8A; Sun, 30 Jan 2005 11:33:09 +0100 (CET) Date: Sun, 30 Jan 2005 11:33:09 +0100 From: Xavier Leroy To: Radu Grigore Cc: brogoff , caml-list Subject: Re: [Caml-list] cyclic types Message-ID: <20050130103309.GD4213@yquem.inria.fr> References: <7f8e92aa0501290415321a8e46@mail.gmail.com> <6b8a914205012905427c79cd85@mail.gmail.com> <7f8e92aa05012909335800c97@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f8e92aa05012909335800c97@mail.gmail.com> User-Agent: Mutt/1.3.28i X-Miltered: at concorde with ID 41FCB7E7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41FCB7E5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 -rectypes:01 recursive:01 ocaml:01 typechecker:01 variants:01 recursive:01 -rectypes:01 val:01 arises:01 expression:01 compile:01 cyclic:01 int:01 objects:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: > For now I have setteled for > type forest = Forest of forest StringMap.t This is a very reasonable thing to do. That, or compile with -rectypes. > Can you give an example of why rectypes by default is dangerous? Recursive types don't break type soundness and are handled fine by the OCaml typechecker -- objects and variants use them in an essential way. The "danger" is that they cause obviously wrong code to pass type-checking and receive "impossible" recursive types, so you notice the problem not at the point of definition of the bad code, but at point of use. A simplified example is this: let f x = x :: x where the author of that code really intended let f x = x @ x With -rectypes, the wrong definition (with ::) is accepted with type val f : ('a list as 'a) -> 'a list = and it's only when you try to apply f to a "normal" list that the problem arises, with a hard-to-understand error message: f [1;2;3];; ^ This expression has type int but is here used with type 'a list as 'a - Xavier Leroy