我有一个生成表单列表的函数: [(String1, exp1); (字符串2,exp2);... ETC]
exp 是我之前定义的类型。
我现在需要一种方法来确定这样的列表是否无效。如果一个列表有一个重复的字符串,但每一个都有不同的 exp 配对,则它是无效的。IE:
[("y", exp1); ("y", exp2); ("x", exp3)] //Invalid, as "y" is repeated with different exps
[("y", exp1); ("y", exp1); ("x", exp3)] //Valid, as "y" is repeated with the same exps
我已经为此寻找合适的解决方案,并尝试使用模式匹配但没有任何运气。我缺少一个简单的解决方案吗?谢谢!