<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><div id="yiv1009391497">Hi John,<br><br>Yes, I see now what the hullabaloo was about.<br><br>I've only been hacking Haskell for a few weeks, so I'm still seeing the "forest" rather than the "trees". But I'm coming along.<br><br>Thanks.<br><br>Michael<br><br>--- On <b>Sat, 4/18/09, John Dorsey <i>&lt;haskell@colquitt.org&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: John Dorsey &lt;haskell@colquitt.org&gt;<br>Subject: Re: [Haskell-cafe] General function to count list elements?<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: haskell-cafe@haskell.org<br>Date: Saturday, April 18, 2009, 2:36 PM<br><br><div class="plainMail">Michael,<br><br>&gt; I had a count function that worked fine for an enum type, but thought<br>&gt; why not go polymorphic with it. So I changed it and got
 the error I<br>&gt; originally inquired about.<br><br>For variety, I'll go a slightly different direction.<br><br>If you generalize count to use any predicate, instead of
 always<br>equality...<br><br>&nbsp;&nbsp;&nbsp; gcount :: (a -&gt; a -&gt; Bool) -&gt; a -&gt; [a] -&gt; Int<br>&nbsp;&nbsp;&nbsp; gcount pred x0 xs = length (filter (pred x0) xs)<br><br>&nbsp;&nbsp;&nbsp; count = gcount (==)<br><br>This will work with any type that you can write a predicate for with the<br>type (a -&gt; a -&gt; Bool).&nbsp; I can even use this with functions, if I'm<br>careful.<br><br>&nbsp;&nbsp;&nbsp; ghci&gt; gcount (\f g -&gt; True)&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;(*2) [id,(const 1),(*3)]<br>&nbsp;&nbsp;&nbsp; 3<br>&nbsp;&nbsp;&nbsp; ghci&gt; gcount (\f g -&gt; f 1 == g 1) (^2) [id,(const 1),(*3)]<br>&nbsp;&nbsp;&nbsp; 2<br><br>By the way, do you see why everyone's bothing you about comparing<br>functions?&nbsp; The type you gave count, which didn't have an Eq constraint,<br>was an assertion that you could compare two values of *any* type.&nbsp; If<br>there's a type that's not comparable, then count's type was wrong.<br>Functions
 are the canonical example of an incomparable type.<br><br>When you're bored some time, read a bit about the Curry-Howard<br>correspondence.&nbsp; It's interesting, even if (like me) you don't grok all<br>of its implications.<br><br>Regards,<br>John<br><br></div></blockquote></div></td></tr></table><br>