Skip to content

Conflicting definitions error does not print explicit quantifiers when necessary

-- Y.hs-boot
{-# LANGUAGE ScopedTypeVariables #-}
module Y where
f :: forall a b. (a, b)

-- YY.hs
module YY where
import {-# SOURCE #-} Y

-- Y.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Y where
import YY
f :: forall b a. (a, b)
f = undefined

I get the following unhelpful error:

ezyang@sabre:~$ ghc-8.0 --make Y.hs -fforce-recomp
[1 of 3] Compiling Y[boot]          ( Y.hs-boot, Y.o-boot )
[2 of 3] Compiling YY               ( YY.hs, YY.o )
[3 of 3] Compiling Y                ( Y.hs, Y.o )

Y.hs-boot:3:1: error:
    Identifier ‘f’ has conflicting definitions in the module
    and its hs-boot file
    Main module: f :: (a, b)
    Boot file:   f :: (a, b)
    The two types are different

Yes this example is purposely shooting itself in the foot, but in the wild I encountered an un-annotated type which inferred a different quantifier ordering than what I expected, and I subsequently spent a while puzzling over the error message. -fprint-explicit-foralls is a sufficient workaround.

Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information