ghc-6.2 bug in type inference

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Fri Feb 6 06:13:57 EST 2004


The following program gives a weird type inference error for me in
ghc-6.2, but compiles perfectly fine in ghc-5.04.2, ghc-6.0, nhc98,
Hugs, etc.

    module Bug ( mkRational ) where
    import Ratio
 
    data Lex = L_RATIONAL Rational
 
    mkRational :: Integer -> Integer -> Integer -> Integer -> Lex
    mkRational i s m e = L_RATIONAL ((((i*s+m)%s)::Rational)*10^^e)

The error I get is this:

    Bug.hs:7:
    Couldn't match `Integer' against `t -> t1'
        Expected type: Integer
        Inferred type: t -> t1
    Probable cause: `((i * s)
                      + m)' is applied to too many arguments in the call
        (((i * s) + m) %s)
    When checking the type signature of the expression:
          (((i * s) + m) %s) :: Rational

The extra-weird thing is that I have evidence that this code used to
compile fine with ghc-6.2 until a few days ago, and I have neither
changed the compiler nor the code...  The only possible change that
I can remember is that I installed the FGL library package at about
the time this started to fail.

Aha.  So I looked at the installed ghc-6.2 package.conf file, and
discovered that the FGL package has:

     extra_ghc_opts = ["-fglasgow-exts", ...]

and indeed, if I give the -fglasgow-exts flag explicitly to ghc-5.04.2,
ghc-6.0, etc, the code fails with the same type error.

So there are two faults here.

    *  package extra-ghc-opts are propagated to all compilations, whether
       those compilations use that package or not.

    *  -fglasgow-exts makes perfectly reasonable Haskell'98 code
       invalid, throws up a totally misleading error unrelated to the
       cause of the problem, and gives no clue as to what particular
       extension is responsible.

Regards,
    Malcolm


More information about the Glasgow-haskell-bugs mailing list