On 8/02/2011, at 10:00 AM, Andrew Coppin wrote:
> I clearly have my languages mixed up.
> 
> The language I'm thinking of required all variables (even top-level ones) to 
> be declared with "let" - unless the definition is recursive, in which case 
> you have to say "letrec" (i.e., the compiler it too stupid to deduce this 
> automatically). Apparently that isn't Clean...

That sounds like an ML-family language, possibly OCAML.

However, this is *not* a question of stupidity.  It's a question of scope rules.

Example 1:

let f x = 1;;
let f x = if x = 0 then 0 else f x;;
f 3;;

This answers 1.

Example 2:

let f x = 1;;
let rec f x = if x = 0 then 0 else f x;;
f 3;;

This goes into an infinite loop.

If you don't like redeclaration, which is rather useful in an interactive
top level, try nested:

let f x = 1;;
let g y = let f x = if x = 0 then 0 else f x in f (f y);;

vs

let f x = 1;;
let g y = let rec f x = if x = 0 then 0 else f x in f (f y);;

The distinction between let and letrec predates OCAML.  Scheme does it too.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to