Haskell - 解析错误/使用多个 where 子句
当尝试定义一个函数来删除集合 m 的最大子集(同时也是集合 a 中集合 a 的子集)时,我遇到了以下错误:
filename.hs:7:33:parse error (possibly incorrect indentation)
对于以下代码:
exclude :: Integral t => [t] -> [t] -> [t]
a `exclude` m
| m == [] = a
| a == (b ++ c) = b
| otherwise = []
where b /= []
where c = [z | z <- m]
如何实现多个条件/定义(使用 where 或其他方式),或更正函数以以不同的方式正常工作?
when trying to define a function that would remove the largest subset of set m that is also a subset of set a from set a, I encountered the following error:
filename.hs:7:33:parse error (possibly incorrect indentation)
for the following code:
exclude :: Integral t => [t] -> [t] -> [t]
a `exclude` m
| m == [] = a
| a == (b ++ c) = b
| otherwise = []
where b /= []
where c = [z | z <- m]
how do I implement multiple conditions/definitions (using where or otherwise), or correct the function to properly work in a different way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题的一部分很容易回答。您可以在一个
where
子句中拥有多个定义,例如,您可以嵌套
where
子句。但在where
子句中,只能有定义。条件将进入守卫(或右侧的if then else
表达式),并且可以与布尔运算符(&&)
、组合>(||)
,not
...至于你的代码,到目前为止我还没有弄清楚你打算做什么。
One part of your question is easily answerable. You can have multiple definitions in one
where
clause, as inand you can have nested
where
-clauses. But in awhere
-clause, you can only have definitions. Conditions would go into the guards (orif then else
expressions on the right hand side) and can be combined with the boolean operators,(&&)
,(||)
,not
...As for your code, so far I haven't figured out what you intended it to do.
说“集合
m
的最大子集也是集合a
的子集”与“
m
的所有元素也是a
的元素”相同。那么问题的解决方案简单地表述为:
当应用于
m
时,将为您提供m
对任何元素取模的子集它们也是
a
的成员。也就是说,它将“删除最大的子集m
也是a
的子集”。Saying "the largest subset of set
m
that is also a subset of seta
"is the same as saying "all elements of
m
that are also elements ofa
".Then the solution to your problem is stated simply as:
which when applied to
m
will give you a subset ofm
modulo any elementsthat are also members of
a
. That is, it will "remove the largest subset ofm
that is also a subset ofa
".事实上,Data.List和Data.Set中都有一个函数叫做“\”。我将展示 Data.List 的 '\' 函数。
In fact,there is a function in Data.List and Data.Set called '\'. I'll show '\' function of Data.List .