如果值为true,则haskell中列表上的fold函数返回true

Nic*_*las 0 haskell

我试图获得一个带有foldr的函数来处理具有3> 4,...等值的列表,如果列表中的值为true,则返回True.我到目前为止尝试过这样做:

fold :: [Bool] -> Bool
fold xs = foldr (x==True) xs
        where x:xs
Run Code Online (Sandbox Code Playgroud)

chi*_*chi 5

你想and xs"和"一个布尔列表.同等地,foldr (&&) True xs或者all id xs也是有效的.

回想一下,它foldr采用了一个函数(例如(&&))和一个基本情况(例如True).你的代码缺乏这两者.