Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7016 closed bug (invalid)

Declarations after top-level splice are ignored

Reported by: Oblosys Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.4.2
Keywords: Cc:
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Declarations that appear after a top-level splice seem to be ignored without any warning. In the attached Main, the identifier afterSplice is not recognized:

Main.hs:6:11: Not in scope: `afterSplice' 

The error disappears if the declaration of afterSplice is put before dummySplice, or if the declaration for problem is removed (in which case afterSplice is declared correctly, as can be seen with in ghci.)

I could track the problem back to at least ghc-7.0.4.

Attachments (2)

Main.hs (164 bytes) - added by Oblosys 8 years ago.
TH.hs (121 bytes) - added by Oblosys 8 years ago.

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by Oblosys

Attachment: Main.hs added

Changed 8 years ago by Oblosys

Attachment: TH.hs added

comment:1 Changed 8 years ago by simonpj

difficulty: Unknown
Resolution: invalid
Status: newclosed

This is by design, as described in Section 7.2 of the original Template Haskell paper.

I agree it's not ideal, but it's not accidental, and I don't know of a better way.

Hmm. It may be that some of the changes mooted in my New directions for Template Haskell post (which I plan to work in on August) may change this.


comment:2 Changed 8 years ago by Oblosys

Ah, so it's a feature! :-) Perhaps this could be briefly mentioned in the documentation? (right after the quieter and less intimidating example). I thought it was a bug because I couldn't find it there and the error message didn't mention Template Haskell.

It's just a small issue, but since I use TH to derive type classes for data declarations, the most appropriate place for the splice would be close to the data declaration. (Each data type is also accompanied by a function declaration, which causes the scoping issues.)

I will await the changes from the new directions post!

-- Martijn

Note: See TracTickets for help on using tickets.