以下代码将在运行时失败(仅限)
do {(x:xs) <- return "";return x}
使用user error (Pattern match failure in do expression at ...
有没有办法为这种潜在错误启用编译器警告?
知道某些破坏性模式匹配可能会失败,在一般情况下处理此问题的最佳方法是什么。
谢谢
答案 0 :(得分:1)
改为使用case
表达式:
do
case "" of
[] -> undefined -- or whatever else you want to do
(x:xs) -> return x
希望有所帮助。