Why is the tail call optimization not used in this Haskell program?
问题 The following program blows the stack: __find_first_occurrence :: (Eq b) => b -> [b] -> Int -> Int __find_first_occurrence e [] i = -1 __find_first_occurrence e (x:xs) i | e == x = i | otherwise = __find_first_occurrence e xs (i + 1) find_first_occurrence :: (Eq a) => a -> [a] -> Int find_first_occurrence elem list = __find_first_occurrence elem list 0 main = do let n = 1000000 let idx = find_first_occurrence n [1..n] putStrLn (show idx) Fails with Stack space overflow: current size 8388608