too liberal handling of instance imports?
Claus Reinke
claus.reinke at talk21.com
Wed Nov 9 18:49:27 EST 2005
I was pretty sure this is a well-known and long-standing bug, but I
can't find it in the sf bug tracker, and the user guide "Known bugs"
section claims in 12.1.1.5 "None known", so I thought I'd ask here.
The problem, as I recall it, is that ghc's import chasing collects
instances as it follows dependencies, without respecting the
actual import relationships between modules. For instance, the
following compiles, but shouldn't (in my understanding, at least:-):
---------------------------------------------
module A where
f = print ((Left "hi" >>= Right) :: Either String String)
---------------------------------------------
module B where
import Control.Monad.Error()
---------------------------------------------
module Main where
import B
import A
main = f
---------------------------------------------
Could someone please confirm that this is a bug, not a mis-
understanding? Switching the order of imports in Main should
not have an impact on program correctness, but it does (win xp,
ghci 6.4.1; missing instance (Monad (Either String))). Similarly,
after a failed load (with flipped imports) in ghci, a simple
:m +Control.Monad.Error
:m -Control.Monad.Error
:r
should not succeed, but it does.
In a larger program (think of A and B as independent sub-projects,
from different vendors..), this is even harder to track (btw, can one
infer the compilation order from ghc -M output? I was at a loss
trying to find out why a certain module A was compiled at the time
it was, for one order of imports, but not for another - when the
compilation of A fails, the modules that caused A to be compiled
have yet to appear in the output.. ).
Cheers,
Claus
More information about the Glasgow-haskell-bugs
mailing list