Is it possible to apply eta reduction in below case?
let normalise = filter (\x -> Data.Char.isLetter x || Data.Char.isSpace x )
I was expecting something like this to be possible:
let normalise = filter (Data.Char.isLetter || Data.Char.isSpace)
...but it is not
Your solution doesn't work, because
(||)
works onBool
values, andData.Char.isLetter
andData.Char.isSpace
are of typeChar -> Bool
.pl gives you:
Explanation:
liftM2
lifts(||)
to the(->) r
monad, so it's new type is(r -> Bool) -> (r -> Bool) -> (r -> Bool)
.So in your case we'll get:
You could take advantage of the
Any
monoid and the monoid instance for functions returning monoid values:Another solution worth looking at involves arrows!
&&&
takes two functions (really arrows) and zips together their results into one tuple. We then just uncurry||
so it's time becomes(Bool, Bool) -> Bool
and we're all done!