[Haskell-cafe] Remove redundancy with Template Haskell

Daniel Trstenjak daniel.trstenjak at gmail.com
Wed Mar 27 22:33:49 CET 2013


Hi Corentin,

On Wed, Mar 27, 2013 at 09:13:41PM +0100, Corentin Dupont wrote:
> I have a function that looks like this:
> call :: SomeFunction -> String -> SomeState
> 
> The string is actually the representation of the function passed in
> parameter. It is stored in the state for documentation.
> So a call looks like that:
> call (\a -> putStrLn a)   "\a -> putStrLn a"
> 
> There is a clear redundancy here, how could I remove it with Template
> Haskell?
> I cannot figure out...

You can even use cpp to get something like:

#define CALL(func) call (func) #func

CALL(\a -> a + 1) => call (\a -> a + 1) "\a -> a + 1"


Greetings,
Daniel



More information about the Haskell-Cafe mailing list