Skip to content

Default methods not in scope for spliced-in instances?

This is a literate haskell bugreport. Save it to
DefaultMethodScopeTH.lhs.

I noticed a problem with instantiating a typeclasse
from Template
Haskell in the same module that defined it. I've bumped
into this
twice close together now, so I figure I really ought to
report it now.

> {-# OPTIONS_GHC -fth #-}
> 
> module DefaultMethodScopeTH where

First, define a typeclass with a default method.

This is probably not a very usefull class, but nobody
wants me to drag
half of the module I'm actually working on into this ;-).

> class Foo a where
>     foo :: a -> a
>     foo = id

Now try to instantiate it from TH with the default method.

> $([d| instance Foo () where |])

Nothing particularly complicated, right?

But when I try to actually build it, I get this:

$ ghc --make DefaultMethodScopeTH.lhs
Chasing modules from: DefaultMethodScopeTH.lhs
Compiling DefaultMethodScopeTH (
DefaultMethodScopeTH.lhs, DefaultMethodScopeTH.o )

DefaultMethodScopeTH.lhs:22:7:
    GHC internal error: `DefaultMethodScopeTH.$dmfoo'
is not in scope
    In the definition of `foo': foo =
DefaultMethodScopeTH.$dmfoo
    In the definition for method `foo'
    In the instance declaration for `Foo ()'

Kind of nasty, eh?
Trac metadata
Trac field Value
Version 6.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution ResolvedFixed
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information