-- helper function fib' a b accum i x = if x == 0 then 1 else if x == 1 then 1 else if i == x then accum else (fib' b (a + b) (a + b) (i + 1) x) -- calculate the xth fibonacci number fib x = fib' 0 1 0 0 x