
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))) []]] ]

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?
Write some combinators for the more common patterns. Some example patterns are: Types: T1 -> ... -> Tn (T1, ... Tn) TC T1 ... Tn Expressions: \ x1 ... xn -> ... let x = e in ... case e of { (x1,...xn) -> ... } f e1 ... en I posted some (in the hope that they'd make it into a standard library) here: http://www.haskell.org/pipermail/template-haskell/2003-September/000176.html And, of course, the TH library includes some (but not enough). -- Alastair Reid www.haskell-consulting.com
participants (2)
-
Alastair Reid
-
MR K P SCHUPKE