[Template-haskell] deriving data Foo = Foo { unFoo :: String } ?

Marc Weber marco-oweber at gmx.de
Sun May 25 08:51:14 EDT 2008


=============  TestX.hs ==============================================

module TestX where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

mkADT :: String -> String -> Q [Dec]
mkADT n t = let n' = mkName n
                un = mkName $ "un" ++ n
             in return [DataD [] n' [] [RecC n' [(un,NotStrict,ConT un)]] []]

============= Main.hs ================================================

-- peckages: template-haskell 
{-# OPTIONS_GHC -XTemplateHaskell #-}
module Main where
import TestX

$( mkADT "Test" "String") 
main = putStrLn . unTest $ Test "test"

============= error ==================================================

test.hs|1 error| 
||     Illegal type constructor or class name: `unTest'
||     When splicing generated code into the program

=============  =======================================================

What am I doing wrong?

Thanks Marc Weber


More information about the template-haskell mailing list