[Haskell-cafe] Template Haskell - substitution in pattern in a
aslatter at gmail.com
Sun Jan 3 21:41:13 EST 2010
On Sun, Jan 3, 2010 at 8:30 PM, Patrick Caldon <patc at pessce.net> wrote:
> I'm trying to write some template haskell which will transform:
> $(buildCP 0) into \(SimpleM d1 d2 d3) (SimpleM _ _ _) -> (SimpleM d1 d2 d3)
> $(buildCP 1) into \(SimpleM _ d2 d3) (SimpleM d1 _ _) -> (SimpleM d1 d2 d3)
> $(buildCP 1) into \(SimpleM d1 _ d3) (SimpleM _ d2 _) -> (SimpleM d1 d2 d3)
> and so on.
> Ultimately I want to generalize this to more variables.
> I can't seem to get anything to substitute for the pattern variables in a
> lambda. Is there a straightforward way of doing this?
It looks like you want to construct expressions with the LamE
constructor, which is declared like so:
LamE [Pat] Exp
For the Pat, you would use eiter VarP or WildP for variable binding
patterns or wild-card patterns.
Or am I missing something?
More information about the Haskell-Cafe