ghc-7.10:非类型变量参数(使用 FlexibleContexts 允许这样做)
ghc-7.10: Non type-variable argument (Use FlexibleContexts to permit this)
我尝试使用 ghc-7.10 (RC 2) 并在很多情况下收到此消息,例如,
src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5:
Non type-variable argument
in the constraint: Text.Parsec.Prim.Stream s m Char
(Use FlexibleContexts to permit this)
When checking that ‘prop’ has the inferred type
prop :: forall s u (m :: * -> *) (t :: * -> *).
(Foldable t, Text.Parsec.Prim.Stream s m Char) =>
Char -> t Char -> Text.Parsec.Prim.ParsecT s u m [Char]
In an equation for ‘isCategory'’:
isCategory'
= (foldr1 (<|>) . map (uncurry prop)
$ [('L', "ultmo"), ('M', "nce"), ('N', "dlo"), ....])
<?> "illegal Unicode character property"
where
prop c1 cs2
= do { _ <- char c1;
.... }
Failed to install hxt-regex-xmlschema-9.2.0
这肯定是新ghc引入的东西,或者是它自带的新base,或者是新的parsec(3.1.8),因为它以前工作过。
源代码片段:
isCategory' :: Parser String
isCategory'
= ( foldr1 (<|>) . map (uncurry prop) $
[ ('L', "ultmo")
, ('M', "nce")
, ('N', "dlo")
, ('P', "cdseifo")
, ('Z', "slp")
, ('S', "mcko")
, ('C', "cfon")
]
) <?> "illegal Unicode character property"
where
prop c1 cs2
= do
_ <- char c1
s2 <- option ""
( do
c2 <- satisfy (`elem` cs2)
return [c2] )
return $ c1:s2
注意:我不是在询问这个特定的库 (hxt-*),因为我在其他地方也观察到了这一点。
This was a change introduced in GHC 7.10.1-rc1:
GHC now checks that all the language extensions required for the inferred type signatures are explicitly enabled. This means that if any of the type signatures inferred in your program requires some language extension you will need to enable it. The motivation is that adding a missing type signature inferred by GHC should yield a program that typechecks. Previously this was not the case.
This is a breaking change. Code that used to compile in the past might fail with an error message requiring some particular language extension (most likely -XTypeFamilies
, -XGADTs
or -XFlexibleContexts
).
我在按照 here 所述设置准系统 Snap 应用程序后遇到此错误。
"" ++ ""
或 "Haskell" !! 2
等字符串操作已损坏。当从 GHCI 获取 Haskell 文件时,我得到了这个错误的变体:
No instance for (Data.String.IsString [a0])
arising from the literal "my string"'
The type variable
a0' is ambiguous
Relevant bindings include myString :: [a0] (bound at myFile.hs:11:1)
Note: there is a potential instance available:
instance Data.String.IsString [Char] -- Defined in Data.String'
In the expression: "my string"
In an equation for
variable': variable = "my string"
解法:
解决此问题的方法是从我项目的 .ghci
文件中删除行 :set -XOverloadedStrings
并重新启动 GHCI。
我的代码也有同样的问题,一部分使用了秒差距,另一部分没有。大多数这些都指向 where
块中没有签名的函数。
对我有用的解决方案是为函数添加显式签名,您可以在其中大部分使用从错误中获得的推断类型,而不是保留 ParsecT s u m [Char]
等类型,我提供我想要的具体类型,比如Parsec String () [Char]
。
我尝试使用 ghc-7.10 (RC 2) 并在很多情况下收到此消息,例如,
src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5:
Non type-variable argument
in the constraint: Text.Parsec.Prim.Stream s m Char
(Use FlexibleContexts to permit this)
When checking that ‘prop’ has the inferred type
prop :: forall s u (m :: * -> *) (t :: * -> *).
(Foldable t, Text.Parsec.Prim.Stream s m Char) =>
Char -> t Char -> Text.Parsec.Prim.ParsecT s u m [Char]
In an equation for ‘isCategory'’:
isCategory'
= (foldr1 (<|>) . map (uncurry prop)
$ [('L', "ultmo"), ('M', "nce"), ('N', "dlo"), ....])
<?> "illegal Unicode character property"
where
prop c1 cs2
= do { _ <- char c1;
.... }
Failed to install hxt-regex-xmlschema-9.2.0
这肯定是新ghc引入的东西,或者是它自带的新base,或者是新的parsec(3.1.8),因为它以前工作过。
源代码片段:
isCategory' :: Parser String
isCategory'
= ( foldr1 (<|>) . map (uncurry prop) $
[ ('L', "ultmo")
, ('M', "nce")
, ('N', "dlo")
, ('P', "cdseifo")
, ('Z', "slp")
, ('S', "mcko")
, ('C', "cfon")
]
) <?> "illegal Unicode character property"
where
prop c1 cs2
= do
_ <- char c1
s2 <- option ""
( do
c2 <- satisfy (`elem` cs2)
return [c2] )
return $ c1:s2
注意:我不是在询问这个特定的库 (hxt-*),因为我在其他地方也观察到了这一点。
This was a change introduced in GHC 7.10.1-rc1:
GHC now checks that all the language extensions required for the inferred type signatures are explicitly enabled. This means that if any of the type signatures inferred in your program requires some language extension you will need to enable it. The motivation is that adding a missing type signature inferred by GHC should yield a program that typechecks. Previously this was not the case.
This is a breaking change. Code that used to compile in the past might fail with an error message requiring some particular language extension (most likely
-XTypeFamilies
,-XGADTs
or-XFlexibleContexts
).
我在按照 here 所述设置准系统 Snap 应用程序后遇到此错误。
"" ++ ""
或 "Haskell" !! 2
等字符串操作已损坏。当从 GHCI 获取 Haskell 文件时,我得到了这个错误的变体:
No instance for (Data.String.IsString [a0]) arising from the literal
"my string"' The type variable
a0' is ambiguous Relevant bindings include myString :: [a0] (bound at myFile.hs:11:1) Note: there is a potential instance available: instance Data.String.IsString [Char] -- Defined inData.String' In the expression: "my string" In an equation for
variable': variable = "my string"
解法:
解决此问题的方法是从我项目的 .ghci
文件中删除行 :set -XOverloadedStrings
并重新启动 GHCI。
我的代码也有同样的问题,一部分使用了秒差距,另一部分没有。大多数这些都指向 where
块中没有签名的函数。
对我有用的解决方案是为函数添加显式签名,您可以在其中大部分使用从错误中获得的推断类型,而不是保留 ParsecT s u m [Char]
等类型,我提供我想要的具体类型,比如Parsec String () [Char]
。