The problem is that you must note in the type signature the fact that
'a' must be a member of typeclass Eq in order to be able to use ==
count :: (Eq a) = a - [a] - Int
count x ys = length (filter (== x) ys)
JP
michael rice wrote:
Is there a general function to count list elements. I'm trying
I find it easier to understand when looking at the declarative meaning
of the definition. There is the trivial case of the empty list, but for
the non-empty list:
The possible inits of the list is the empty list and the inits of the
rest of the list with the head element it their front.
The
:) [[2], [3], [4]]
Prelude map (1:) [[2], [3], [4]]
[[1,2],[1,3],[1,4]]
Because:
map f [[2], [3], [4]] = [f [2], f [3], f [4]]
So let f = (x:) then:
map f [[2], [3], [4]] = [(1:) [2], (1:) [3], (1:) [4]]
= [[1, 2], [1, 3], [1, 4]]
JP
Juan Pedro Bolivar Puente wrote:
I
and Visual Haskell had some unique features (such as hovering tooltips
showing types) that are now found in the F# editor, and should now be easier
to implement with the recent GHC API (I guess).
haskell-mode for Emacs does show the type signature of standard
functions in the mini-buffer when