【发布时间】:2012-06-14 02:30:15
【问题描述】:
我有以下受歧视的工会:
type ActCard = Cellar of card list
| Chapel of (card option * card option* card option* card option)
| Smithy | Spy of (card -> bool * card -> bool)
在我将card -> bool 添加到Spy 之前,它具有结构平等性。 This question 有助于如何对记录进行自定义相等。但是,我不确定在这种情况下如何最好地实施它。我宁愿不必在ActCard 中列举每个案例:
override x.Equals(yobj) =
match x, yobj with
| Spy _, Spy _ -> true
| Cellar cards, Cellar cards2 -> cards = cards2
(* ... etc *)
这里有什么更好的方法?
【问题讨论】: