<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><ekirpichov@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Eugene Kirpichov <ekirpichov@gmail.com><br>Subject: Re: [Haskell-cafe] General function to count list elements?<br>To: "michael rice" <nowgate@yahoo.com><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 -> x) (replicate 10 (\y -> if 1==1 then y else undefined))<br><br>return?<br><br>2009/4/18 michael rice <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>>:<br>> Is there a general function to count list elements. I'm trying this<br>><br>> count :: a -> [a] -> Int<br>> count x ys = length (filter (== x) ys)<br>><br>> with this error upon loading<br>><br>> =============<br>><br>> [michael@localhost ~]$ ghci count<br>> GHCi, version 6.10.1: <a href="http://www.haskell.org/ghc/%C2%A0" target="_blank">http://www.haskell.org/ghc/ </a> :? for help<br>> Loading package ghc-prim ... linking ... done.<br>> Loading package integer ... linking ... done.<br>> Loading package base ... linking ... done.<br>> [1 of 1] Compiling Main (
count.hs, interpreted )<br>><br>> count.hs:2:29:<br>> Could not deduce (Eq a) from the context ()<br>> arising from a use of `==' at count.hs:2:29-32<br>> Possible fix:<br>> add (Eq a) to the context of the type signature for `count'<br>> In the first argument of `filter', namely `(== x)'<br>> In the first argument of `length', namely `(filter (== x) ys)'<br>> In the expression: length (filter (== x) ys)<br>> Failed, modules loaded: none.<br>> Prelude><br>><br>> =============<br>><br>> Not sure what it's trying to tell me other than I need an (Eq a) somewhere.<br>><br>> Michael<br>><br>><br>><br>><br>> _______________________________________________<br>> Haskell-Cafe mailing list<br>> <a
ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>><br>><br><br><br><br>-- <br>Eugene Kirpichov<br>Web IR developer, market.yandex.ru<br></div></blockquote></td></tr></table><br>