From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DA3F9BC8A for ; Sun, 30 Jan 2005 07:46:42 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0U6kg3c023762 for ; Sun, 30 Jan 2005 07:46:42 +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 HAA06533 for ; Sun, 30 Jan 2005 07:46:41 +0100 (MET) Received: from mail21.sea5.speakeasy.net (mail21.sea5.speakeasy.net [69.17.117.23]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0U6kdiD023759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 30 Jan 2005 07:46:41 +0100 Received: (qmail 9446 invoked from network); 30 Jan 2005 06:46:38 -0000 Received: from shell3.sea5.speakeasy.net ([69.17.116.4]) (envelope-sender ) by mail21.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 30 Jan 2005 06:46:38 -0000 Date: Sat, 29 Jan 2005 22:46:38 -0800 (PST) From: brogoff To: skaller Cc: caml-list Subject: Re: [Caml-list] cyclic types In-Reply-To: <1107032560.23562.527.camel@pelican.wigram> Message-ID: References: <7f8e92aa0501290415321a8e46@mail.gmail.com> <6b8a914205012905427c79cd85@mail.gmail.com> <1107032560.23562.527.camel@pelican.wigram> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 41FC82D2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41FC82CF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 wrote:01 -rectypes:01 -rectypes:01 rec:01 ocaml:01 foo:01 ocaml:01 recursion:01 recursive:01 workarounds:01 speakeasy:01 exception:01 typing: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: On Sat, 30 Jan 2005, skaller wrote: > On Sun, 2005-01-30 at 04:12, brogoff wrote: > > This comes up relatively frequently, and it is known that having -rectypes > > as the default is not a good idea. However, wouldn't explicit typing of > > this case sidestep the known problems and eliminate the need for a > > -rectypes option here? > > Do you mean something like: > > type rec forest = forest StringMap.t > > where the 'rec' means 'just this type is meant to be cyclic' > (and treat that type as if -rectypes had been given)? No, I meant just accept the cyclic types as we do now with -rectypes, but annotate the functions that use them, something like this (pseudo OCaml) type ('a, 'b) t = 'a * (('a , 'b) t -> 'b) list let foo : 'a -> (('a * ('b -> 'c) list as 'b) -> 'c = fun n m -> (List.assoc n m) m Nice huh, the type is longer than the actual code :-(. Anyways, I rememeber someone complaining about the overhead of the connstructor wrapping in order to do this in real OCaml (that is, without -rectypes) and this does away with that. If it were just cyclic types, it wouldn't be a big deal, but there are other places that explicit types driving the typing could pay off. There are a couple of ways to get nonuniform recursion in OCaml but (with the exception of perhaps the *experimental* recursive module feature) they're clunky workarounds. The right way is just to annotate the functions with their types. -- Brian