Why doesn't pattern matching on a property of a record compile?

后端 未结 2 1620
借酒劲吻你
借酒劲吻你 2021-01-27 23:49

Why doesn\'t pattern matching on a property of a record compile?

type Cell = { X:int; Y:int }

let isNeighbor cell1 cell2 =
    match cell1.X, c         


        
2条回答
  •  春和景丽
    2021-01-28 00:25

    When you do

    match cell1.X, cell2.X with
    | cell1, cell2
    

    you have created a new cell1 variable, which is cell1.X (an int).

    I would probably have just used an if here, or change to | _,_ when ...

提交回复
热议问题