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 51EB4BC48 for ; Wed, 27 Apr 2005 21:14:37 +0200 (CEST) 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 j3RJEa7V015120 for ; Wed, 27 Apr 2005 21:14:37 +0200 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 VAA06291 for ; Wed, 27 Apr 2005 21:14:36 +0200 (MET DST) Received: from us18.unix.fas.harvard.edu (us18.unix.fas.harvard.edu [140.247.35.198]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j3RJEZ2C015116 for ; Wed, 27 Apr 2005 21:14:36 +0200 Received: from [140.247.161.186] (roam161-186.student.harvard.edu [140.247.161.186]) by us18.unix.fas.harvard.edu (8.12.11/8.12.11) with ESMTP id j3RJEYGm015076 for ; Wed, 27 Apr 2005 15:14:34 -0400 Mime-Version: 1.0 (Apple Message framework v622) Content-Transfer-Encoding: 7bit Message-Id: Content-Type: text/plain; charset=US-ASCII; format=flowed To: caml-list@inria.fr From: Mike Hamburg Subject: type-checking difficulties in recursive functions Date: Wed, 27 Apr 2005 15:14:33 -0400 X-Mailer: Apple Mail (2.622) X-Miltered: at concorde with ID 426FE49D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 426FE49B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; recursive:01 recursive:01 recursion:01 trivial:01 rec:01 foo:01 foo:01 val:01 bool:01 bool:01 checker:01 rec:01 'string:01 'string:01 val:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: I'm having trouble with a recursive function which tries to use itself, instantiated to a different type, in the recursion. As a trivial example similar to what I want to do, consider: let rec foo p x = if p then x else let something = foo false "Hello" in x;; val foo : bool -> string -> string = Now, foo is actually safe as a function from bool -> 'a -> 'a, but the recursive declaration doesn't generalize and so the checker doesn't realize this. With magic, I can get the right type relatively safely by writing let rec string_foo p : 'string -> 'string = Obj.magic foo p and foo p x = if p then x else let something = string_foo false "Hello" in x;; val string_foo : bool -> string -> string = val foo : bool -> 'a -> 'a = but is there a way to avoid magic? Thanks, Mike Hamburg P.S. I couldn't find the bug in my Netcgi program, but by deleting and rewriting part of it, I got it working :-)