【发布时间】:2011-10-29 22:12:01
【问题描述】:
让我们考虑以下Point 记录类型:
type Point = { x:int; y:int }
我想创建一个谓词,告诉我给定点是否在有效区域中。
let insideBounds p =
let notInside c = c < 0 || c > 100
match p with
| {x=i; y=_} when notInside i -> false
| {x=_; y=j} when notInside j -> false
| _ -> true
这行得通,但我想知道是否有另一种方法可以实现与 insideBounds 签名相同的结果
let insideBounds {x=i; y=j}
相反,仍然使用模式匹配?
【问题讨论】:
标签: .net f# functional-programming pattern-matching