You're partially right. The Typeable is redundant because Data has the type:<br><br>(Typeable a) => Data a<br><br clear="all">-R. Kyle Murphy<br>--<br>Curiosity was framed, Ignorance killed the cat.<br>
<br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 15:01, Ozgur Akgun <span dir="ltr"><<a href="mailto:ozgurakgun@gmail.com">ozgurakgun@gmail.com</a>></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;">
Why do you need them to be Typeable? toConstr has the following type:<br><br>toConstr :: (Data a) => a -> Constr<br><br>Best,<div><div></div><div class="h5"><br><br><div class="gmail_quote">On 3 August 2010 19:50, Kyle Murphy <span dir="ltr"><<a href="mailto:orclev@gmail.com" target="_blank">orclev@gmail.com</a>></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;">I was close, this actually does what was asked:<br><br>import Data.Data<br><br>typeChecker :: (Typeable a, Typeable b, Data a, Data b) => a -> b -> Bool<br>
typeChecker a b = toConstr a == toConstr b<div><br><br clear="all">
-R. Kyle Murphy<br>--<br>Curiosity was framed, Ignorance killed the cat.<br>
<br><br></div><div><div></div><div><div class="gmail_quote">On Tue, Aug 3, 2010 at 14:42, Kyle Murphy <span dir="ltr"><<a href="mailto:orclev@gmail.com" target="_blank">orclev@gmail.com</a>></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;">
Actually looking at the original question I'm not sure my code does what was intended. I was looking at does some type (a b) == (a c), which wasn't exactly the question. Oh well, back to the drawing board.<div>
<br><br clear="all">
-R. Kyle Murphy<br>--<br>Curiosity was framed, Ignorance killed the cat.<br>
<br><br></div><div><div></div><div><div class="gmail_quote">On Tue, Aug 3, 2010 at 14:38, Kyle Murphy <span dir="ltr"><<a href="mailto:orclev@gmail.com" target="_blank">orclev@gmail.com</a>></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;">
Less of a dirty dirty hack (requires that SchemeVal be an instance of Typeable):<br><br>import Data.Typeable<br>import Data.Maybe<br><br>typeChecker :: (Typeable a, Typeable b) => a -> b -> Bool<br>typeChecker a b = f a == f b<br>
where<br> f :: (Typeable a) => a -> Maybe TypeRep<br> f = listToMaybe . typeRepArgs . typeOf<br><br><br clear="all">-R. Kyle Murphy<br><font color="#888888">--<br>Curiosity was framed, Ignorance killed the cat.</font><div>
<div></div><div><br>
<br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 13:51, Alex Rozenshteyn <span dir="ltr"><<a href="mailto:rpglover64@gmail.com" target="_blank">rpglover64@gmail.com</a>></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;">
<div dir="ltr">That is a dirty, dirty hack.<div><div></div><div><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" target="_blank">Christian.Maeder@dfki.de</a>></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;">Matt Andrew schrieb:<br>
<div>> 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><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" target="_blank">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></div></div><div>-- <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></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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>
<br></blockquote></div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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>
<br></blockquote></div><br><br clear="all"><br>-- <br></div></div><font color="#888888">Ozgur Akgun<br>
</font></blockquote></div><br>