我想通过前两个值在集合中找到元组并返回元组的第三个值(或者如果没有找到,则为None)。我喜欢这样的东西:从F#中的元组集合中获取元素
type Point = (int * int * int)
type Path = Set<Point>
let f (x:int) (y:int) (p:Path) : int Option =
if Set.exists ((=) (x, y, _z)) p
then Some _z
else None
let p:Path = Set.ofList [ (0, 1, 100); (1, 1, 500); (1, 2, 50); ]
f 1 2 p
但是这不起作用,因为显然,表达式中不允许模式匹配。什么是正确的方法?谢谢。
基于两步法的方法有什么问题? –
什么是_z' ..? – ildjarn
@John Palmer你是什么意思?首先,找到元组,然后从中提取值? – Feofilakt