Transforming a function to point-free style changes its type

后端 未结 3 1166
独厮守ぢ
独厮守ぢ 2021-02-19 04:35

I\'m beginning Haskell... I tried to write the following trivial function in two different ways, letting Haskell decide the types, and the type system does something different i

3条回答
  •  -上瘾入骨i
    2021-02-19 05:08

    As others have pointed out, this is caused by something called the "Monomorphism Restriction".

    MR can be useful for writers of Haskell compilers, and there is controversy about whether or not it is worthwhile to have in the language in general. But there is one thing everyone agrees: at the GHCi prompt, MR is nothing but a nuisance.

    MR will probably be turned off by default in this context in an upcoming version of GHC. For now, you should disable it in GHCi by creating a text file called ".ghci" in your home directory that contains a line like this:

    :set -XNoMonomorphismRestriction
    

提交回复
热议问题