I have a case where a Haskell missing parentheses compiles fine but enters an infinite loop. Here is my code with the working version commented out:
$ cat main.hs
fib :: Int -> Int
fib 0 = 1
fib 1 = 1
fib n =
let
fib_n_minus_2 = fib n-2
-- fib_n_minus_2 = fib (n-2)
fib_n_minus_1 = fib (n-1)
in
fib_n_minus_2+
fib_n_minus_1
main :: IO ()
main = putStrLn $ show $ fib 7
When I compile it everything goes fine, but when I run the resulting program it gets stuck. Why is that? I imagine the compiler parses fib n,
then goes on to see -2 fib_n_minus_1 where it should stop and issue an error, right?