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

后端 未结 3 754
遥遥无期
遥遥无期 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:52

    The process you are talking about is called supercompilation and it's more difficult than you make it out to be. It is actually one of the active research topics in computing science! There are some people that are trying to create such a supercompiler for Haskell (probably based on GHC, my memory is vague) but the feature is not included in GHC (yet) because the maintainers want to keep compilation times down. You mention C++ as a language that does this – C++ also happens to have notoriously bad compilation times!

    Your alternative for Haskell is to do this optimisation manually with Template Haskell, which is Haskells compile-time evaluated macro system.

提交回复
热议问题