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 5E7D7BC37 for ; Tue, 9 Feb 2010 23:18:08 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuABAG9tcUvUnwdjkGdsb2JhbACDCZddFQEBAQEJCQwHEwQfrR6QQIEvgkpbBA X-IronPort-AV: E=Sophos;i="4.49,438,1262559600"; d="scan'208";a="56560519" Received: from relay.pcl-ipout01.plus.net ([212.159.7.99]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Feb 2010 23:18:08 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAF9ucUtUXebz/2dsb2JhbACDCZdddK0akECBL4JKWwQ Received: from relay02.plus.net ([84.93.230.243]) by relay.pcl-ipout01.plus.net with ESMTP; 09 Feb 2010 22:18:07 +0000 Received: from [87.112.77.220] (helo=leper.local) by relay02.plus.net with esmtp (Exim) id 1NeyPG-000745-PH; Tue, 09 Feb 2010 22:18:07 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: saptarshi.guha@gmail.com, caml-list@yquem.inria.fr Subject: Re: [Caml-list] The need to specify 'rec' in a recursive function defintion Date: Tue, 9 Feb 2010 23:33:39 +0000 User-Agent: KMail/1.9.9 References: <1e7471d51002091250of7a686fq537a03c9401c868f@mail.gmail.com> In-Reply-To: <1e7471d51002091250of7a686fq537a03c9401c868f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201002092333.39698.jon@ffconsultancy.com> X-Plusnet-Relay: c6c86a797cd5ee4a1dc7ac6c374a8a73 X-Spam: no; 0.00; recursive:01 defintion:01 recursive:01 ocaml:01 compiler:01 compiler:01 ocaml:01 frog:98 unbound:01 wrote:01 stack:01 rec:01 rec:01 caml-list:01 functions:01 On Tuesday 09 February 2010 20:50:33 Saptarshi Guha wrote: > Hello, > I was wondering why recursive functions need to be specified with > "rec". According to Practical Ocaml, to "inform the compiler that the > function exists". But when entering the function definition, can't the > compiler note that the function is being defined so that when it sees the > function calling itself, it wont say "Unbound value f"? > > How is the knowledge of a function being rec taken advantage of (in > ocaml) as opposed to other languages > (leaving aside tail call optimization). > > Wouldn't one of way of detecting a recursive function would be to see > if the indeed the function calls itself? let f x = x + 1 let f x = 2 * f x Is the latter "f" recursive or not? See my answer to the same question on stack overflow: http://stackoverflow.com/questions/900585/why-are-functions-in-ocaml-f-not-recursive-by-default/1891573 -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e