Browse thread
The need to specify 'rec' in a recursive function defintion
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-02-09 (22:18) |
From: | Jon Harrop <jon@f...> |
Subject: | Re: [Caml-list] The need to specify 'rec' in a recursive function defintion |
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