ghc-7.10:非类型变量参数(使用FlexibleContexts允许此操作)

d8d*_*f42 14 haskell parsec ghc

我试图使用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
Run Code Online (Sandbox Code Playgroud)

这必须是由新的ghc或它附带的新基础或新的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
Run Code Online (Sandbox Code Playgroud)

注意:我不是在询问这个特定的库(hxt-*),因为我在其他地方也观察过这个.

bhe*_*ilr 19

这是GHC 7.10.1-rc1中引入的更改:

GHC现在检查是否明确启用了推断类型签名所需的所有语言扩展.这意味着如果您的程序中推断出的任何类型签名需要一些语言扩展,您将需要启用它.动机是添加由GHC推断的缺失类型签名应该产生一个类似于程序的程序.以前情况并非如此.

这是一个突破性的变化.这在过去使用编译的代码可能会失败,需要一些特定的语言扩展的错误消息(最有可能的-XTypeFamilies,-XGADTs-XFlexibleContexts).

  • @engineerDave是的,如果您为您的cabal项目全局启用了`OverloadedStrings`,然后使用`cabal repl`启动了ghci,就会发生这种情况.我之前也遇到过,这不只是一个菜鸟问题! (2认同)