Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is eta reduction possible?

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

like image 383
st4hoo Avatar asked May 07 '14 13:05

st4hoo


1 Answers

Your solution doesn't work, because (||) works on Bool values, and Data.Char.isLetter and Data.Char.isSpace are of type Char -> Bool.

pl gives you:

$ pl "f x = a x || b x"
f = liftM2 (||) a b

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:

import Control.Monad
let normalise = filter (liftM2 (||) Data.Char.isLetter Data.Char.isSpace)
like image 107
Benesh Avatar answered Oct 14 '22 08:10

Benesh