When can eta reduction change a function's type?

后端 未结 1 1827
夕颜
夕颜 2021-01-12 23:54

What exactly is going on with the following?

> let test = map show

> :t test
test :: [()] -> [String]

> :t (map show)
(map show) :: Show a =>         


        
相关标签:
1条回答
  • 2021-01-13 00:51

    This is the monomorphism restriction, which applies when a binding doesn't take parameters and allows the binding to be shareable when it otherwise wouldn't be due to polymorphism, on the theory that if you don't give it a parameter you want to treat it as something "constant"-ish (hence shared). You can disable it in ghci with :set -XNoMonomorphismRestriction; this is often useful in ghci, where you often intend such expressions to be fully polymorphic. (In a Haskell source file, make the first line

     {-# LANGUAGE NoMonomorphismRestriction #-}
    

    instead.)

    0 讨论(0)
提交回复
热议问题