haskell - 是什么导致了 "irrefutable pattern failed for pattern",它是什么意思?

标签 haskell pattern-matching runtime-error

做什么

irrefutable pattern failed for pattern



意思是?
什么情况会导致这个运行时错误?

最佳答案

考虑这个例子:

foo ~(Just x) = "hello"
main = putStrLn $ foo Nothing

这使用了一个无可辩驳的模式(~ 部分)。无可辩驳的模式总是“匹配”,所以打印 hello .
foo ~(Just x) = x
main = putStrLn $ foo Nothing

现在,模式仍然匹配,但是当我们尝试使用 x当它实际上不存在时,我们得到了一个无可辩驳的模式匹配错误:
Irr.hs: /tmp/Irr.hs:2:1-17: Irrefutable pattern failed for pattern (Data.Maybe.Just x)

这与没有匹配模式时得到的错误有细微的不同:
foo (Just x) = x
main = putStrLn $ foo Nothing

这输出
Irr.hs: /tmp/Irr.hs:2:1-16: Non-exhaustive patterns in function foo

当然,这是一个有些人为的例子。更可能的解释是它来自 let 中的模式。绑定(bind), as chrisdb suggested .

关于haskell - 是什么导致了 "irrefutable pattern failed for pattern",它是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6711870/

相关文章:

wcf - Visual Studio 2012 安装破坏了我的 2010 WCF 项目

ms-access - 运行时错误 13 类型不匹配 VBA Access 2007

haskell - Lisp 有类似 Haskell 的 takeWhile 函数吗?

haskell - GADT 的 : Is there a reason why the weakest or strongest type is not chosen

unit-testing - 对秒差距解析器进行美味的 Hunit 测试?

null - 我应该使用 == 或 'is' 来检查 C# 7 中的 null 吗?

c - 为什么这个简单的 C 程序会在运行时崩溃?

haskell - 试图将包装类型族变成类似 Functor 的东西

Scala 模式匹配在 2.10 中的递归类型上失败

linux - 在 bash 中将文本 append 到具有模式匹配名称的文件