简体   繁体   English

Haskell 中的模式匹配

[英]Pattern matching in Haskell

I am working on a Haskell project and I have some trouble with this code snippet:我正在处理一个 Haskell 项目,但我在使用此代码片段时遇到了一些问题:

buildTowers :: [Int] -> Int ->[[Bool]]
buildTowers [x] max = (buildBoolList x max) :[]
buildTowers (x:xs) max = (buildBoolList x max):buildTowers xs max

I get this error: Non exhausting pattern matches, but for me it seems as everthing is covered.我收到此错误:非耗尽模式匹配,但对我来说似乎涵盖了所有内容。 Do you know what the problem is?你知道问题是什么吗?

Thanks in advance.提前致谢。

As @Reid Barton already pointed out in the comments, you are missing to match the empty list.正如@Reid Barton 已经在评论中指出的那样,您无法匹配空列表。 I'd further go with @Daniel Wagners suggestion, merging both in this community answer so the question can be closed.我会进一步采纳@Daniel Wagners 的建议,将两者合并到这个社区的答案中,这样问题就可以结束了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM