[Haskell-beginners] Type error in function binding

bahadýr altan doaltan at yahoo.co.uk
Mon Apr 2 16:50:41 CEST 2012


Hi.
I'm trying to write a code which counts the number of  'a's  in a string.
it looks like this :

mycounter st =
if st == [] then 0
else if head st == 'a' then 1 + mycounter tail st else mycounter tail st

but it gives this error : 
ERROR "deneme.hs":19 - Type error in function binding
*** Term           :mycounter
*** Type           : [Char] -> b
*** Does not match : ([a] -> [a]) -> [Char] -> b
*** Because        : unification would give infinite type

I have no idea about what I'm doing wrong. Can you help me with this please?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120402/dfb3fd9e/attachment.htm>


More information about the Beginners mailing list