如何派生以下自定义类型的相等类型类?
type Address =
{ street :: String
, city :: String
, state :: String
}
type Entry =
{ firstName :: String
, lastName :: String
, address :: Address
}
derive instance eqEntry :: Eq Entry
编译时我收到以下错误:
Cannot derive a type class instance, because the type declaration for Entry could not be found.
这让我很困惑,因为我可以看到 Entry 的类型声明就在派生类型类的语句之上。
最佳答案
类型同义词不能有类实例。为了拥有实例,您必须将 Entry
声明为 data
或 newtype
:
newtype Entry = Entry
{ firstName :: String
, lastName :: String
, address :: Address
}
derive instance eqEntry :: Eq Entry
关于purescript - 如何为用户定义类型派生类型类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49671178/