我在 ghci 7.6.3 中尝试了以下内容
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>
有人可以告诉我发生了什么吗?
谢谢。