[Haskell-beginners] implicit or shorthand class instances?

Alexander Bernauer alex-haskell at copton.net
Fri Nov 30 14:42:43 CET 2012


On Thu, Nov 29, 2012 at 12:52:38PM -0900, Christopher Howard wrote:
> Is there any special extension or syntax trick that would allow me to
> reduce the amount of this repetitious code?

I am not aware of any (which doesn't mean there is none).

I would hack a few lines of Template Haskell for this. Should be pretty
straight forward.

Use the thee quotation operator like so
---8<---
[| {- code -} |] 
--->8---
to get the Haskell AST of this code snippet and pretty print it. Then
you have a good starting point for what your TH function should return.

Note, that if the TH function returns 'Q [Dec]' you don't need a splice
operator for top-level declarations. Instead, you can simply write 
---8<---
data SomeThing = ....

instantiate 'SomeThing
--->8---
where instantiate is your TH function.

Pretty handy, IMHO.

See [1] for a starting point.

HTH

Alex

[1]
http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/template-haskell.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121130/f831fe8f/attachment.pgp>


More information about the Beginners mailing list