小编Jav*_*rgz的帖子

插入功能中缺少模式

我有这个功能inserts,其中

inserts 1 [2,3] = [[1,2,3],[2,1,3],[2,3,1]]
Run Code Online (Sandbox Code Playgroud)

这是定义(直接来自Bird和Gibbons的Haskell算法设计)

inserts :: a -> [a] -> [[a]]
inserts x [] = [[x]]
inserts x (y:ys) = (x:y:ys) : map (y:) (inserts x ys)
Run Code Online (Sandbox Code Playgroud)

我已经用上面的例子在 ghci 中尝试过,但我得到以下异常

[[1,2,3],[2,1,3]*** Exception: <interactive>:2:1-53: Non-exhaustive patterns in function inserts
Run Code Online (Sandbox Code Playgroud)

有谁知道缺少的模式是什么?

haskell ghci non-exhaustive-patterns multiline-repl-definition

1
推荐指数
1
解决办法
59
查看次数