小编goi*_*ain的帖子

Extension OverloadedString不完全推断IsString.为什么?或者我错过了什么?

ghc 7.6.3

对于我正在尝试编译的一些代码感到非常沮丧

错误是

No instance for (Data.String.IsString t3)
arising from the literal `"meh"'
The type variable `t3' is ambiguous
Run Code Online (Sandbox Code Playgroud)

我不明白.这是一个文字.什么是暧昧的?为什么不能把它推断为一个字符串?

这就像是一个电话

foo bar "meh"
Run Code Online (Sandbox Code Playgroud)

在哪里foo不要求第二个参数特别是任何东西(它必须满足一些typeclass,并且它对它所获得的特定组合有效.)

我会注意到我可以通过更改呼叫来修复此错误

foo bar ("meh" :: String)
Run Code Online (Sandbox Code Playgroud)

这显然是疯了.

- 编辑

也许它与overloadedStrings无关

我可以"重现"这个错误

data B a where
    Foo :: a -> B A
Run Code Online (Sandbox Code Playgroud)

然后在GHCi写作简单

Foo "ok"
Run Code Online (Sandbox Code Playgroud)

(显然这失败了因为我没有得到Show,但为什么我也得到了

No instance for (Data.String.IsString a0)
    arising from the literal `"ok"'
  The type variable `a0' is ambiguous
  ...
Run Code Online (Sandbox Code Playgroud)

?这里发生了什么?这是什么意思?)

haskell

5
推荐指数
1
解决办法
1137
查看次数

标签 统计

haskell ×1