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 A6E17BC8B for ; Sun, 30 Jan 2005 12:36:34 +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 j0UBaYCI031440 for ; Sun, 30 Jan 2005 12:36:34 +0100 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 MAA15542 for ; Sun, 30 Jan 2005 12:36:34 +0100 (MET) Received: from smtp003.mail.ukl.yahoo.com (smtp003.mail.ukl.yahoo.com [217.12.11.34]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id j0UBaXYZ031434 for ; Sun, 30 Jan 2005 12:36:33 +0100 Received: from unknown (HELO ?82.121.26.228?) (sejourne?kevin@82.121.26.228 with plain) by smtp003.mail.ukl.yahoo.com with SMTP; 30 Jan 2005 11:36:33 -0000 Message-ID: <41FCC893.6090208@yahoo.fr> Date: Sun, 30 Jan 2005 12:44:19 +0100 From: sejourne_kevin User-Agent: Mozilla Thunderbird 1.0 (X11/20050116) X-Accept-Language: fr, en MIME-Version: 1.0 To: caml-list Cc: Xavier Leroy Subject: Re: [Caml-list] cyclic types References: <7f8e92aa0501290415321a8e46@mail.gmail.com> <6b8a914205012905427c79cd85@mail.gmail.com> <7f8e92aa05012909335800c97@mail.gmail.com> <20050130103309.GD4213@yquem.inria.fr> In-Reply-To: <20050130103309.GD4213@yquem.inria.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 41FCC6C2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41FCC6C1.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 compiler:01 expression:01 compile:01 cyclic:01 int:01 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: Xavier Leroy a écrit : >>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 It should be nice this kind of explanations is available in the documentation of the compiler rather than on a mailing list. Kévin