Why are (constant) expressions not evaluated at compile time in Haskell?

后端 未结 3 749
遥遥无期
遥遥无期 2020-12-10 15:11

I am currently learning Haskell, and there is one thing that baffles me:

When I build a complex expression (whose computation will take some time) and this expressio

3条回答
  •  轮回少年
    2020-12-10 15:37

    In this case, GHC can not be sure that the computation would finish. It's not a question of lazy versus strict, but rather the halting problem. To you, it looks quite simple to say that treeFromlist [0..90000] is a constant that can be evaluated at compile time, but how does the compiler know this? The compiler can easily optimize [0..90000] to a constant, but you wouldn't even notice this change.

提交回复
热议问题