<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Though I haven't tried it out, it's trying to use my function to count functions.<br><br>The first argument is the identity function.<br><br>The second argument is a list of a different form of the identity function.<br><br>Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal.<br><br>So my guess at an answer would be zero.<br><br>Michael<br><br>--- On <b>Sat, 4/18/09, Eugene Kirpichov <i>&lt;ekirpichov@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Eugene Kirpichov &lt;ekirpichov@gmail.com&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, 11:03 AM<br><br><div
 class="plainMail">What should<br><br>count (\x -&gt; x) (replicate 10 (\y -&gt; if 1==1 then y else undefined))<br><br>return?<br><br>2009/4/18 michael rice &lt;<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;:<br>&gt; Is there a general function to count list elements. I'm trying this<br>&gt;<br>&gt; count :: a -&gt; [a] -&gt; Int<br>&gt; count x ys = length (filter (== x) ys)<br>&gt;<br>&gt; with this error upon loading<br>&gt;<br>&gt; =============<br>&gt;<br>&gt; [michael@localhost ~]$ ghci count<br>&gt; GHCi, version 6.10.1: <a href="http://www.haskell.org/ghc/%C2%A0" target="_blank">http://www.haskell.org/ghc/&nbsp;</a> :? for help<br>&gt; Loading package ghc-prim ... linking ... done.<br>&gt; Loading package integer ... linking ... done.<br>&gt; Loading package base ... linking ... done.<br>&gt; [1 of 1] Compiling Main&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (
 count.hs, interpreted )<br>&gt;<br>&gt; count.hs:2:29:<br>&gt; &nbsp;&nbsp;&nbsp; Could not deduce (Eq a) from the context ()<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `==' at count.hs:2:29-32<br>&gt; &nbsp;&nbsp;&nbsp; Possible fix:<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add (Eq a) to the context of the type signature for `count'<br>&gt; &nbsp;&nbsp;&nbsp; In the first argument of `filter', namely `(== x)'<br>&gt; &nbsp;&nbsp;&nbsp; In the first argument of `length', namely `(filter (== x) ys)'<br>&gt; &nbsp;&nbsp;&nbsp; In the expression: length (filter (== x) ys)<br>&gt; Failed, modules loaded: none.<br>&gt; Prelude&gt;<br>&gt;<br>&gt; =============<br>&gt;<br>&gt; Not sure what it's trying to tell me other than I need an (Eq a) somewhere.<br>&gt;<br>&gt; Michael<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a
 ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>&gt;<br>&gt;<br><br><br><br>-- <br>Eugene Kirpichov<br>Web IR developer, market.yandex.ru<br></div></blockquote></td></tr></table><br>