Skip to content

Template haskell rejects duplicate instances before they're spliced

Suppose I want to see (from within ghci) how to write an instance declaration in the TH AST. I try:

Prelude> runQ $ [d| instance Monad Maybe where |]                                                                                                                                                                                                   
                                                                                                                                                                                                                                             
<interactive>:1:13:                                                                                                                                                                                                                          
    Duplicate instance declarations:                                                                                                                                                                                                         
      instance Monad Maybe -- Defined at <interactive>:1:13-23                                                                                                                                                                               
      instance Monad Maybe -- Defined in Data.Maybe                                                                                                                                                                                          
    In the Template Haskell quotation                                                                                                                                                                                                        
      [d|                                                                                                                                                                                                                                    
          instance Monad Maybe where |]                                                                                                                                                                                                      
    In the expression:                                                                                                                                                                                                                       
        [d|                                                                                                                                                                                                                                  
            instance Monad Maybe where |]                                                                                                                                                                                                    
    In the definition of `it':                                                                                                                                                                                                               
        it = [d|                                                                                                                                                                                                                             
                 instance Monad Maybe where |]

This seems ridiculous; I'm not trying to create an instance, just to create a TH AST fragment.

Trac metadata
Trac field Value
Version 6.12.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
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