Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  implicit or shorthand class instances? (Alexander Bernauer)


----------------------------------------------------------------------

Message: 1
Date: Fri, 30 Nov 2012 14:42:43 +0100
From: Alexander Bernauer <[email protected]>
Subject: Re: [Haskell-beginners] implicit or shorthand class
        instances?
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <20121130134243.GO10200@apus>
Content-Type: text/plain; charset="us-ascii"

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-0001.pgp>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 54, Issue 1
****************************************

Reply via email to