我在Prelude中发现了函数init的两个定义:
init [x] = []
init (x:xs) = x : init xs
init [] = errorEmptyList "init"
init [] = errorEmptyList "init"
init (x:xs) = init' x xs
where init' _ [] = []
init' y (z:zs) = y : init' z zs
Run Code Online (Sandbox Code Playgroud)
第二个定义的原因是什么?
haskell ×1