【发布时间】:2018-03-12 08:51:32
【问题描述】:
所以我正在尝试编写一个函数来返回 l1 和 l2 共有的元素列表,但它每次都返回空,我无法找到它的逻辑错误。 `
let rec intersection (l1 : 'a list) (l2 : 'a list) : 'a list =
let rec aux l1 l2 acc = match l1 with
| [] -> []
| h1::t1 -> begin match l2 with
| [] -> []
| h2::t2 -> if h1 = h2 then aux t1 t2 (h1::acc) else aux l1 t2 acc
end in
aux l1 l2 []
【问题讨论】: