我正在尝试取出1到10之间可以被5或3整除的所有数字。
这是我目前的代码 -
giveList =
[ x
| x <- [1..10] ,
(x `mod` 5 == 0) or (x `mod` 3 == 0)
]
然后我在ghci中加载函数。但是它给了我一个错误 -
> [1 of 1] Compiling Main ( problem1.hs, interpreted )
problem1.hs:4:10:
The function `x `mod` 5 == 0' is applied to two arguments,
but its type `Bool' has none
In the expression: (x `mod` 5 == 0) or (x `mod` 3 == 0)
In a stmt of a list comprehension:
(x `mod` 5 == 0) or (x `mod` 3 == 0)
In the expression:
[x | x <- [1 .. 10], (x `mod` 5 == 0) or (x `mod` 3 == 0)]
Failed, modules loaded: none.
我的问题是 -
- 在列表推导式中,我们能使用 'or' 吗?
- 如果不行,请告诉我其他方法
我刚接触函数式编程,请帮帮我。