[Haskell-cafe] TH clause Pat selection
Brian Lewis
brian at lorf.org
Thu Jun 20 00:23:11 CEST 2013
I want to use TH to generate functions like
foo :: c -> h
foo ... = ...
foo ... = ...
...
from lists of pairs :: [(c, h)]
For example, $(genFoo ''Int ''Bool [(0,False), (1,True)])
would generate
foo 0 = False
foo 1 = True
The problem is, I don't know how to generate the function's clauses.
"foo 0 = ..." seems to be a LitP pattern. But "foo True = ..." seems to
be a ConP pattern. The appropriate pattern depends on type c.
Here's code with more explanation and examples:
http://hpaste.org/90163
More information about the Haskell-Cafe
mailing list