>>15
It works fine by me:
fix (const 1) => 1
let b = fix (\f n -> if n < 1 then 1 else f (n - 1) + f (n - 2))
:t b
b :: Integer -> Integer
b 9
144
What exactly does x = f x do in haskell?
The let is a letrec (if I translate it to scheme), so it should expand to this:
let x = f x in x =>
let x = f (f x) in x =>
let x = f (f (f x)) in x => ..
if I put const 1 in there as f, we get:
let x = const 1 x in x =>
let x = const 1 (const 1 x) in x =>
The compiler knows the second argument expands, but const isn't strict in its second argument, thus it won't expand the expression further.
let x = const 1 <thunk> in x
evaluating gives us:
let x = (\a _ -> a) 1 thunk in x
let x = 1 in x =>
1