1 haskell list set where-clause
当我试图定义一个函数来删除set m的最大子集时,它也是set a的set a的子集,我遇到了以下错误:
filename.hs:7:33:parse error (possibly incorrect indentation)
Run Code Online (Sandbox Code Playgroud)
对于以下代码:
exclude :: Integral t => [t] -> [t] -> [t]
a `exclude` m
| m == [] = a
| a == (b ++ c) = b
| otherwise = []
where b /= []
where c = [z | z <- m]
Run Code Online (Sandbox Code Playgroud)
如何实现多个条件/定义(使用where或其他方式),或者更正函数以正确的方式以不同的方式工作?
问题的一部分很容易回答.您可以在一个where子句中包含多个定义,如
foo n
| even r = bar
| s < 12 = baz
| otherwise = quux
where
r = n `mod` 1357
h = a + b
where
(a,b) = r `divMod` 53 -- nested where-clause
s = r - 3*h
Run Code Online (Sandbox Code Playgroud)
你可以有嵌套的where-clauses.但在一个条款中where,你只能有定义.条件将进入卫兵(或if then else表达式在右手边),可与布尔运算符相结合,(&&),(||),not...
至于你的代码,到目前为止我还没弄清楚你打算做什么.