<div dir="ltr">That is a dirty, dirty hack.<br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 8:45 PM, Christian Maeder <span dir="ltr"><<a href="mailto:Christian.Maeder@dfki.de">Christian.Maeder@dfki.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Matt Andrew schrieb:<br>
<div class="im">> 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's 'Write Yourself a Scheme in 48 hours' 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 -> SchemeVal<br>
> numberP (Number _) = Bool True<br>
> numberP _ = Bool False<br>
><br>
> boolP :: SchemeVal -> SchemeVal<br>
> boolP (Bool _) = Bool True<br>
> boolP _ = Bool False<br>
><br>
> symbolP :: SchemeVal -> 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'm having trouble discovering if/how it's possible to do so elegantly in Haskell. The closest (but obviously incorrect) code to what I'm trying to accomplish would be:<br>
><br>
> typeChecker :: SchemeVal -> SchemeVal -> 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'm trying to accomplish. Anyone have any suggestions?<br>
<br>
</div>typeChecker s1 s2 = let f = takeWhile isAlphaNum . show in<br>
Bool $ f s1 == f s2<br>
<br>
hoping that my "f" just extracts the constructor as string.<br>
<font color="#888888"><br>
C.<br>
</font><div><div></div><div class="h5"><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>
><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div>() ascii ribbon campaign - against html e-mail <div>/\ <a href="http://www.asciiribbon.org" target="_blank">www.asciiribbon.org</a> - against proprietary attachments</div>
</div><div><br></div><div> Alex R</div><br>
</div>