Opened 12 years ago

Closed 12 years ago

Last modified 47 years ago

#383 closed bug (Fixed)

Default methods not in scope for spliced-in instances?

Reported by: sbronson Owned by: simonpj
Priority: normal Milestone:
Component: Template Haskell Version: 6.4
Keywords: Cc:
Operating System: Architecture:
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


This is a literate haskell bugreport. Save it to

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 )

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

Kind of nasty, eh?

Attachments (1)

DefaultMethodScopeTH.2.lhs (1.2 KB) - added by sbronson 12 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 12 years ago by sbronson

Logged In: YES 

Ugg, this looks horrible. That'll teach me to write bug
reports in Emacs, I guess... the autogenerated email looks
very slightly better, but not much. I'm attaching the original.

Changed 12 years ago by sbronson

Attachment: DefaultMethodScopeTH.2.lhs added

comment:2 Changed 12 years ago by simonpj

Status: assignedclosed
Logged In: YES 

Good bug report, thanks.

Now fixed, and the fix will be in 6.4.1
Note: See TracTickets for help on using tickets.