【发布时间】:2013-03-21 09:35:18
【问题描述】:
我想在 Ocaml 中编写一个函数,它给出一个四元组和一个四元组 (x,y,z,f),返回一个包含元组 (x',y',z',g) 的列表这样 x = x' 或 y=y' 或 z = z' (这些是整数)。这是我的第一次尝试
let rec constrained_by c list =
match s with
| []-> []
| hd :: tl ->
begin
let Cell(x,y,r,_)= c in (*warning*)
begin
match hd with
| Cell(x,_,_,Some(_))-> hd::constrained_by c tl
| Cell(_, y, _,Some(_)) -> hd::constrained_by c tl
| Cell(_, _, r,Some(_)) -> hd::constrained_by c tl
| _ -> constrained_by c tl
end
end
问题:当它被调用时,无论我们匹配什么四元组,它都会返回原始列表。 此外,问题在于它返回警告,即第 (warning) 行的 x,y, r 未使用。
【问题讨论】:
标签: pattern-matching ocaml unused-variables