gpt4 book ai didi

haskell - 或采用两个值参数 haskell

转载 作者:行者123 更新时间:2023-12-05 08:24:34 28 4
gpt4 key购买 nike

我是 haskell 的初学者,我试图为埃拉托色尼筛法定义一个简单的函数,但它说错误:

    • Couldn't match expected type ‘Bool -> Bool’
with actual type ‘Bool’
• The function ‘or’ is applied to two value arguments,
but its type ‘t Bool -> Bool’ has only one
In the expression: or (mod n x) (divl l x)
In an equation for ‘divl’: divl (n : l) x = or (mod n x) (divl l x)
|
13 | divl (n:l) x = or (mod n x) (divl l x)
erat l [] = l
erat l (x:t) = if divl l x then erat l t else erat (x:t) l

divl (n:l) x = or (mod n x) (divl l x)
divl [] x = True

我试着把它写成带有“`”的运算符,但没有成功

最佳答案

or 不是 bool OR 运算符;那是 (||)or 获取 bool 值列表(好吧,Foldable),如果至少有一个值为 True,则返回 True .

> or []
False
> or [True, False]
True

(请注意,或[]被定义为False以保留身份或xs || or ys == or (xs++ ys) 。作为具体示例,或[] || 或[False] == 或[False]。)

关于haskell - 或采用两个值参数 haskell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75178190/

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