【发布时间】:2014-05-29 10:49:10
【问题描述】:
我需要为数据派生 Eq,但对于某些构造函数,我想忽略一些 字段。 数据用于表示 DataTypes(我们正在开发编译器):
data DataType
= Int | Float | Bool | Char | Range | Type
| String Width
| Record (Lexeme Identifier) (Seq Field) Width
| Union (Lexeme Identifier) (Seq Field) Width
| Array (Lexeme DataType) (Lexeme Expression) Width
| UserDef (Lexeme Identifier)
| Void | TypeError
deriving (Ord)
我需要从它出现的每个构造函数中忽略Width 字段。
【问题讨论】:
-
到目前为止你尝试过什么?顺便说一句,您将自动派生
Ord,这意味着它将按Width订购。所以你可能会发现自己有两个DataType值a和b,所以a>b和a==b都是正确的——这似乎不是一个好主意。
标签: haskell compiler-construction derived-instances