gpt4 book ai didi

haskell - 在 haskell 中重新定义 'all' 函数

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

<分区>

如何使用 foldr 重新定义 haskell 中的 all 函数?我试过这样写,但我不确定为什么它不起作用。

all :: (a -> Bool) -> [a] -> Bool
all p (x:xs) = foldr (&&) True ((p x) : (all p xs))

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