zipper:返回从焦点位置开始的子列表 |但为什么当 n > 0 时?

问题描述 投票:0回答:0

我发现这种类型

zipper
get
函数定义如下:

type 'a zipper = 'a list * int
Exception Empty

let empty = ([], 0)
(* get: returns the sublist starting at focus position *)
let rec get lz = 
  match lz with
  | (l, 0) -> l 
  | (h::t, n) when n > 0 -> get (t, n-1)
  | _ -> raise Empty

但是我不清楚

when n > 0
,那是没有必要的,因为assuming我们将提供参数
n > 0
,它总是会被第一场比赛捕获,这不是正确的吗?为什么是
when n > 0

functional-programming ocaml
© www.soinside.com 2019 - 2024. All rights reserved.