Я попробовал следующее 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
Pro tip: включить «большую жирную ошибку» в отчет о проблеме. –