Generating function implementations from a list of patterns
29 Nov
2009
29 Nov
'09
4:27 p.m.
Hi list, I'm trying to generate function implementations given a list of patters to match the function argument. For example, given data Foo = Foo Int | Bar Int foobar (Foo i) = i foobar (Bar i) = i The body of the "foobar" function is the same for all the patterns, therefore I'd like to generate it. In particular, I'd like to be able to write something like (pseudo-template-haskell) $(genFunc ''foobar [(''Foo i), (''Bar i)] i) i.e. have a function genFunc which takes the name of the function to define, the list of patterns and the function body as arguments. I've played around with the example for deriving Show on the wiki, but I didn't really get anywhere. Any pointers how to do this? Thanks, Lars
5881
Age (days ago)
5881
Last active (days ago)
0 comments
1 participants
participants (1)
-
Lars Kotthoff