gpt4 book ai didi

haskell - 我怎么能优雅地不。 Haskell有吗?

转载 作者:行者123 更新时间:2023-12-02 02:30:46 25 4
gpt4 key购买 nike

我试图弄清楚如何否定两个参数 bool 函数的结果,如 not . any .我理解为什么它不能通过如下所示的分解来工作,但我不确定如何编写一个优雅地执行此操作的函数。我设法做到了curry $ not . uncurry any

Prelude> :t not
not :: Bool -> Bool

Prelude> :t any
any :: Foldable t => (a -> Bool) -> t a -> Bool

Prelude> :t (.)
(.) :: (b -> c) -> (a -> b) -> a -> c

curry $ not . uncurry any
:: Foldable t => (a -> Bool) -> t a -> Bool

最佳答案

有一个标准的 point-free-ifier,可独立使用或通过 lambdabot 使用,它提供:

18:02 <dmwit> ?pl \f xs -> any (\x -> not (f x)) xs
18:02 <lambdabot> any . (not .)
18:04 <dmwit> ?pl \f xs -> not (any f xs)
18:04 <lambdabot> (not .) . any

many ways to spell this general operation .

编辑:感谢 zudov对于以下建议的额外文本:您也可以访问 pointfree安装工具 pointfree 或使用 Web 界面之一(例如 http://pointfree.io )。

关于haskell - 我怎么能优雅地不。 Haskell有吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29836916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com