Why this Haskell code never terminates?

后端 未结 2 590
粉色の甜心
粉色の甜心 2021-01-18 22:44

I recently wrote some Haskell code and it never terminates. After I carefully examined my code, the problem boiled down to the following code piece

main :: I         


        
2条回答
  •  北海茫月
    2021-01-18 23:24

    The second binding (a = a) shadows the other one. The first example is (almost) exactly equivalent to

    main = print $ let xyz = 10 in
                   let a = a in
                   a :: Int
    

    and I hope it's clear why that one doesn't terminate! You can get GHC to warn you about this by using the -fwarn-name-shadowing flag (or by entering :set -fwarn-name-shadowing in GHCi)

提交回复
热议问题