Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghc-7.10: Non type-variable argument (Use FlexibleContexts to permit this)

I was trying to use ghc-7.10 (RC 2) and got this message in a number of cases, e.g.,

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

This must be something that is introduced by the new ghc, or the new base that comes with it, or the new parsec (3.1.8), since it worked before.

source code snippet:

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

Note: I am not asking about this specific libray (hxt-*) since I observed this in other places also.

like image 928
d8d0d65b3f7cf42 Avatar asked Feb 02 '15 21:02

d8d0d65b3f7cf42


2 Answers

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).

like image 112
bheklilr Avatar answered Oct 23 '22 05:10

bheklilr


I'm having the same issue with my code, part of it that uses Parsec and part of it that doesn't. Most all of these point to functions without signatures in a where block.

The solution that works for me is to add explicit signatures for the functions, where you can use the inferred type you get from the error for the most part, but rather than keeping types such as ParsecT s u m [Char] generic, I supply the concrete type I want, such as Parsec String () [Char].

like image 26
MicroVirus Avatar answered Oct 23 '22 03:10

MicroVirus