[Haskell-cafe] filterFirst

Jonathan Cast jcast at ou.edu
Mon Jul 23 14:32:04 EDT 2007

On Monday 23 July 2007, Alexteslin wrote:
> Hi,
> first I like to thank all of you guys - it really helps!
> I am still on a same chapter with higher order functions and this function
> is also confusing.
> But before i even define this function i am getting the type error - i
> don't know why? So i wrote the simpler one like:
> filterAlpha :: (a -> Bool) -> [a] -> [a]
> filterAlpha f [] = []
> filterAlpha f (x:xs)
> 	|f x 	= x : filterAlpha xs
> 	|otherwise	= filterAlpha xs
> and i am getting this error message:
> Type error in application
> Expression :filterAlpha xs
> Type        : [b]
> Dous not match : a -> Bool
> To even my very little knowledge i think that this should work. What am i
> doing wrong?

You're passing only one argument to filterApha, when it takes two.  Haskell 
can't figure out which arguments you want to stay the same on every recursive 
call, and which ones you want to vary, so you have to supply every argument 
every time.

Jonathan Cast

More information about the Haskell-Cafe mailing list