To my understanding, what you want is pattern matching on data constructors. In the following example,<br><br><span style="font-family: courier new,monospace;">data Expr = Num Int</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">          | Plus  Expr Expr</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">          | Minus Expr Expr</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums :: Expr -&gt; Expr</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums (Num i) = Num (i+1)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">incrementNums (Plus  i j) = Plus  (incrementNums i) (incrementNums j)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums (Minus i j) = Minus (incrementNums i) (incrementNums j)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums&#39; :: Expr -&gt; Expr</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums&#39; (Num i) = Num (i+1)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">incrementNums&#39; (cons i j) = cons (incrementNums&#39; i) (incrementNums&#39; j)</span><br><br>You want incrementNums&#39; instead of incrementNums.<br><br>And that&#39;s not possible with this data type. Of course you can always do the following:<br>
<br><span style="font-family: courier new,monospace;">data ExprEnum = Plus | Minus</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data Expr = Num Int</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">          | BinExpr ExprEnum Expr Expr</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums :: Expr -&gt; Expr</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">incrementNums (Num i) = Num (i+1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">incrementNums (BinExpr cons i j) = BinExpr cons (incrementNums i) (incrementNums j)</span><br style="font-family: courier new,monospace;">
<br>Hope this helps. Cheers,<br><br><div class="gmail_quote">On 3 August 2010 12:51, Matt Andrew <span dir="ltr">&lt;<a href="mailto:mjsaand@gmail.com">mjsaand@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi all,<br>
<br>
I am in the process of writing a Scheme interpreter/compiler in Haskell as my first serious project after learning the basics of Haskell. The goal is to really get a feel for Haskell. I am trying to accomplish this as much as I can on my own, but am referring to Jonathan Tang&#39;s &#39;Write Yourself a Scheme in 48 hours&#39; whenever I get really stuck.<br>

<br>
I have a question regarding a pattern that I have found within my code for which I cannot seem to find an abstraction.<br>
<br>
I am implementing some of the primitive Scheme type-checker functions with the following code:<br>
<br>
numberP :: SchemeVal -&gt; SchemeVal<br>
numberP (Number _) = Bool True<br>
numberP _          = Bool False<br>
<br>
boolP :: SchemeVal -&gt; SchemeVal<br>
boolP (Bool _) = Bool True<br>
boolP _        = Bool False<br>
<br>
symbolP :: SchemeVal -&gt; SchemeVal<br>
symbolP (Atom _) = Bool True<br>
symbolP _        = Bool False<br>
<br>
This is a pattern that I could easily provide an abstraction for with a Lisp macro, but I&#39;m having trouble discovering if/how it&#39;s possible to do so elegantly in Haskell. The closest (but obviously incorrect) code to what I&#39;m trying to accomplish would be:<br>

<br>
typeChecker :: SchemeVal -&gt; SchemeVal -&gt; SchemeVal<br>
typeChecker (cons _) (cons2 _) = Bool $ cons == cons2<br>
<br>
I understand this code drastically misunderstands how pattern matching works, but (hopefully) it expresses what I&#39;m trying to accomplish. Anyone have any suggestions?<br>
<br>
I do realise that such an abstraction is barely worth it for the amount of code it will save, but this exercise is about learning the ins and outs of Haskell.<br>
<br>
Appreciate you taking the time to read this,<br>
<font color="#888888"><br>
Matt Andrew<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>