eta减少可能吗? [英] Is eta reduction possible?
本文介绍了eta减少可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
您的解决方案不起作用,因为(||)
可用于 Bool
值,并且 Data.Char.isLetter
和 Data.Char.isSpace
类型为 Char - > Bool
。
Your solution doesn't work, because (||)
works on Bool
values, and Data.Char.isLetter
and Data.Char.isSpace
are of type Char -> Bool
.
pl 给你:
pl gives you:
$ pl "f x = a x || b x"
f = liftM2 (||) a b
说明: liftM2
升降机(||)
到( - >)r
monad,所以它的新类型是(r - > ; Bool) - > (r - > Bool) - > (r - > Bool)
。
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)
这篇关于eta减少可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文