
Well, Template Haskell is what you go to when what you want -can't- be
reasonably expressed with standard GHC Haskell. It's something of a
last resort (at least in my case). Typeclass synonyms can be faked
reasonably well with UndecidableInstances, but if you want to, for
example, automatically generate nontrivial instances of some class for
user-provided types, Template Haskell is frequently what you need to
use.
2010/11/2 Paolino
It's first time I use TH. It would be nice to point out the motivations for using it. If everything TH does is doable without it, the point of using it is write less code, eliminating some necessary and automatically computable code. But I guess there is some more .....
paolino
2010/11/2 Antoine Latter
2010/11/1 Paolino
: I think I've got something nice in the end.
http://hpaste.org/41042/classsynonymhs
example:
class ( ParteDi (Servizio a) s , Read a , Eq a , Show a , Integer `ParteDi` s ) => SClass s a
$(classSynonym ''SClass)
ghci ":i SClass" command is printing some strange type variables but it compiles
Template Haskell might be overkill for this. In the past, I've done:
class (Eq b, Show b, MyClass b, MyOtherClass b) => MySynonym b instance (Eq b, Show b, MyClass b, MyOtherClass b) => MySynonym b
I think this requires a couple of GHC extensions, but TemplateHaskell is an extension as well. Maybe there are pitfalls with this approach.
Antoine
-- Work is punishment for failing to procrastinate effectively.