Template Haskell...

MR K P SCHUPKE k.schupke at imperial.ac.uk
Wed Oct 29 17:46:09 EST 2003

Okay, I have got my template working, but its extremely unreadable... could
anyone tell me how to make this look more like normal Haskell code?

stringType :: String -> Q [Dec]
stringType s = do
   x <- gensym "x"
   return [
      Newtype [] s [] (Constr s [(NonStrict,Tcon (TconName "String"))]) [],
      Proto ("show"++s) (Tapp (Tapp (Tcon Arrow) (Tcon (TconName s))) (Tcon (TconName "ShowS"))),
      Fun ("show"++s) [Clause [Pcon s [Pvar x]] (Normal (App (Var "showString") (Var x))) []],
      Instance [] (Tapp (Tcon (TconName "Show")) (Tcon (TconName s))) [
         Fun "showsPrec" [Clause [Pwild,Pvar x] (Normal (App (Var ("show"++s)) (Var x))) []]] ]

More information about the Glasgow-haskell-users mailing list