我想通過前兩個值在集合中找到元組並返回元組的第三個值(或者如果沒有找到,則爲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