From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B24E3BBAF for ; Wed, 17 Feb 2010 17:35:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AusBAPupe0vUGyoBkWdsb2JhbACDBZd9FQEBAQEJCwoHEwMgrXKPcIEwglFcBA X-IronPort-AV: E=Sophos;i="4.49,492,1262559600"; d="scan'208";a="57187142" Received: from smtp1-g21.free.fr ([212.27.42.1]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 Feb 2010 17:34:32 +0100 Received: from smtp1-g21.free.fr (localhost [127.0.0.1]) by smtp1-g21.free.fr (Postfix) with ESMTP id BC52D940034 for ; Wed, 17 Feb 2010 17:34:27 +0100 (CET) Received: from tenebreuse.gim.name (bob75-4-82-229-193-250.fbx.proxad.net [82.229.193.250]) by smtp1-g21.free.fr (Postfix) with ESMTP id D2B10940169 for ; Wed, 17 Feb 2010 17:34:24 +0100 (CET) Received: by tenebreuse.gim.name (Postfix, from userid 1000) id 84826F6ED; Wed, 17 Feb 2010 17:34:24 +0100 (CET) Date: Wed, 17 Feb 2010 17:34:24 +0100 From: =?utf-8?B?U3TDqXBoYW5l?= Gimenez To: The Caml Mailing List Subject: type generalization of recursive calls Message-ID: <20100217163424.GA38458@tenebreuse> Mail-Followup-To: =?utf-8?B?U3TDqXBoYW5l?= Gimenez , The Caml Mailing List MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam: no; 0.00; gimenez:01 gimenez:01 recursive:01 ocaml:01 recursive:01 syntactical:01 checker:01 pointers:01 cheers:01 phane:98 phane:98 rec:01 recursively:01 pps:01 jussieu:01 Hi, I just realized that ocaml generalizes the type of a recursively defined function *only* for calls which are outside it's own definition. Recursive calls cannot use a generalized type. In fact, I'm tring to work with such a data type: type 'a t = | E | D of 'a t * 'a t | O of 'a | I of 'a t t And, I'm forced to use some dark magic to define simple operations on it: let rec map (f : 'a -> 'b) : 'a t -> 'b t = begin function | E -> E | D (t1, t2) -> D (map f t1, map f t2) | O a -> O (f a) | I tt -> I ((Obj.magic map : ('a t -> 'b t) -> 'a t t -> 'b t t) (map f) tt) end Questions: - Is it theoreticaly safe to generalize recursive calls ? - Is there a syntactical trick to use generalized recursive calls ? - Could such a generalization be added to the type checker ? - Performance issues ? - More obfusctated type checking errors ? In a related disscution I found, one asked about generalization between mutualy recursive definitions (same problem). No answers, but maybe I just lack pointers. Cheers, Stéphane