GHC can't avoid module cycle with class definitions
Problem: Can't avoid a module cycle with class definitions in Haskell.
Foo.hs contains:
module Foo where
import {-# SOURCE #-} Bar
class FooClass a where
...
myBar :: BarClass -> a -- use a class from Bar
...
Foo.hs-boot contains:
module Foo where
import {-# SOURCE #-} Bar
class FooClass a where
...
myBar :: BarClass -> a -- use a class from Bar
...
----------------------
Bar.hs contains:
module Bar where
import Foo
class BarClass a where
...
myFoo :: FooClass -> a -- use a class from Foo
...
Bar.hs-boot contains:
module Bar where
?? import Foo -- causes ghc to report a module cycle
?? import {-# SOURCE #-} Foo -- also causes ghc to report a module cycle
class BarClass a where
...
myFoo :: FooClass -> a -- without import, FooClass is out of scope
...
Command run:
ghc Bar.hs Foo.hs
Removing Foo.hs-boot does NOT fix the problem.
What's the solution?