[GHC] #240: Abysmal Template Haskell error message

GHC trac at galois.com
Fri Oct 13 09:37:58 EDT 2006


#240: Abysmal Template Haskell error message
---------------------------------+------------------------------------------
    Reporter:  mm_aa             |        Owner:  simonpj
        Type:  bug               |       Status:  closed 
    Priority:  low               |    Milestone:         
   Component:  Template Haskell  |      Version:  6.2.1  
    Severity:  normal            |   Resolution:  fixed  
    Keywords:                    |   Difficulty:  Unknown
Architecture:  Unknown           |           Os:  Unknown
---------------------------------+------------------------------------------
Changes (by igloo):

  * architecture:  => Unknown
  * resolution:  None => fixed
  * difficulty:  => Unknown
  * status:  assigned => closed
  * os:  => Unknown

Old description:

> {{{
> Windows XP
>
> D:\Tools\ghc>ghc-6.2.1\bin\ghc.exe -fglasgow-exts --make foo.hs
> Chasing modules from: foo.hs
> Compiling Any              ( ./Any.hs, ./Any.o )
> Compiling Foo              ( foo.hs, foo.o )
> Loading package base ... linking ... done.
> Loading package haskell98 ... linking ... done.
> Loading package haskell-src ... linking ... done.
> ghc.exe: panic! (the `impossible' happened, GHC version 6.2.1):
>         Malformed predicate
>

> module Any where
>
> import Language.Haskell.THSyntax
>
> genAny :: DecQ -> Q [Dec]
> genAny decl =
>     do{
>         d <- decl
>       ; case d of
>             ClassD _ name _ decls -> sequenceQ [genAnyClass
> (name)
> decls]
>             _ -> error "genAny can be applied to classes only"
>     }
>
> genAnyClass :: String -> [Dec] -> DecQ
> genAnyClass name decls =
>     do{
>         returnQ (DataD [forall] anyName [] [constructor] [])
>     }
>     where
>         anyName = "Any" ++ name ++ "1111"
>         constructor = NormalC anyName [(NotStrict, VarT "a")]
>         forall = ForallT [] [] (VarT "a")
>

> module Foo where
>
> import Any
>
> class MyInterface a where
>         foo :: a -> Int
>         foo1 :: Int -> a -> Int
>
> $(genAny (reifyDecl MyInterface))
>
> }}}

New description:

 {{{
 Windows XP

 D:\Tools\ghc>ghc-6.2.1\bin\ghc.exe -fglasgow-exts --make foo.hs
 Chasing modules from: foo.hs
 Compiling Any              ( ./Any.hs, ./Any.o )
 Compiling Foo              ( foo.hs, foo.o )
 Loading package base ... linking ... done.
 Loading package haskell98 ... linking ... done.
 Loading package haskell-src ... linking ... done.
 ghc.exe: panic! (the `impossible' happened, GHC version 6.2.1):
         Malformed predicate


 module Any where

 import Language.Haskell.THSyntax

 genAny :: DecQ -> Q [Dec]
 genAny decl =
     do{
         d <- decl
       ; case d of
             ClassD _ name _ decls -> sequenceQ [genAnyClass
 (name)
 decls]
             _ -> error "genAny can be applied to classes only"
     }

 genAnyClass :: String -> [Dec] -> DecQ
 genAnyClass name decls =
     do{
         returnQ (DataD [forall] anyName [] [constructor] [])
     }
     where
         anyName = "Any" ++ name ++ "1111"
         constructor = NormalC anyName [(NotStrict, VarT "a")]
         forall = ForallT [] [] (VarT "a")


 module Foo where

 import Any

 class MyInterface a where
         foo :: a -> Int
         foo1 :: Int -> a -> Int

 $(genAny (reifyDecl MyInterface))

 }}}

Comment:

 Updating these modules for the various syntax changes:

 {{{
 module Any where

 import Language.Haskell.TH.Syntax
 import Language.Haskell.TH

 genAny :: DecQ -> Q [Dec]
 genAny decl =
     do{
         d <- decl
       ; case d of
             ClassD _ name _ _ decls -> sequenceQ [genAnyClass (name)
 decls]
             _ -> error "genAny can be applied to classes only"
     }

 genAnyClass :: Name -> [Dec] -> DecQ
 genAnyClass name decls =
     do{
         returnQ (DataD [forall] anyName [] [constructor] [])
     }
     where
         anyName = mkName ("Any" ++ nameBase name ++ "1111")
         constructor = NormalC anyName [(NotStrict, VarT (mkName "a"))]
         forall = ForallT [] [] (VarT (mkName "a"))
 }}}

 {{{
 module Foo where

 import Language.Haskell.TH
 import Any

 class MyInterface a where
     foo :: a -> Int
     foo1 :: Int -> a -> Int

 $(genAny (do ClassI d <- reify ''MyInterface
              return d))
 }}}

 we now (with GHC 6.6) get:

 {{{
 $ ghc -fth --make Foo.hs
 [1 of 2] Compiling Any              ( Any.hs, Any.o )
 [2 of 2] Compiling Foo              ( Foo.hs, Foo.o )
 Loading package base ... linking ... done.
 Loading package template-haskell ... linking ... done.

 Foo.hs:1:0:
     Malformed predicate forall . a
     When splicing generated code into the program
 $
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/240>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list