讀VS地圖我試着在ghci中7.6.3在ghci中
prelude> let m = map
上述工作如下。沒有來自GHCi的錯誤。
但後來我想,
prelude> let r = read
上面的代碼拋出GHCI一個大胖子的錯誤。這是錯誤我得到的,
*Main> let r = read
<interactive>:122:9:
No instance for (Read a0) arising from a use of `read'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Read IOMode -- Defined in `GHC.IO.IOMode'
instance Read BufferMode -- Defined in `GHC.IO.Handle.Types'
instance Read Newline -- Defined in `GHC.IO.Handle.Types'
...plus 30 others
In the expression: read
In an equation for `r': r = read
然後我想,
prelude> let r = read :: Read a => String -> a
思維類型簽名會解決的事情。但是再次,我從GHCi得到一個錯誤。確切的錯誤如下,
*Main> let r = read :: Read a => String -> a
<interactive>:123:9:
No instance for (Read a0) arising from an expression type signature
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Read IOMode -- Defined in `GHC.IO.IOMode'
instance Read BufferMode -- Defined in `GHC.IO.Handle.Types'
instance Read Newline -- Defined in `GHC.IO.Handle.Types'
...plus 30 others
In the expression: read :: Read a => String -> a
In an equation for `r': r = read :: Read a => String -> a
*Main>
有人能告訴我發生了什麼事嗎?
謝謝。
你已經遇到了單態限制。 http://www.haskell.org/haskellwiki/Monomorphism_restriction – Sarah
專業提示:在問題報告中包含「大胖子錯誤」。 –