<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">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: http://www.haskell.org/ghc/ :? 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></td></tr></table><br>