小编all*_*ass的帖子

为什么在Prelude中有两个init函数定义?

我在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

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

标签 统计

haskell ×1