GHC should not allow modules to define instances of abstract type classes
hs-boot files permit a type class to be given "abstractly", in which case any implementation of the type class is permissible. But it does not reject instances defined for such a class.
-- A.hs-boot
module A where
class C a
-- B.hs
module B where
import {-# SOURCE #-} A
instance C Int where
-- A.hs
module A where
import B
class C a where
f :: a
-- Main.hs
import A
main = print (f :: Int)
I get this when I build with --make
:
ezyang@sabre:~$ ghc-head --make C.hs -fforce-recomp
[1 of 4] Compiling A[boot] ( A.hs-boot, A.o-boot )
[2 of 4] Compiling B ( B.hs, B.o )
[3 of 4] Compiling A ( A.hs, A.o )
[4 of 4] Compiling Main ( C.hs, C.o )
Linking C ...
./B.o:(.data+0x0): undefined reference to `A_CZCC_con_info'
collect2: error: ld returned 1 exit status