如何为用户定义的类型派生类型类?

How do I derive a typeclass for a user defined type?

如何为以下自定义类型派生相等类型类?

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 的类型声明就在派生类型类的语句之上。

类型同义词不能有 class 个实例。为了拥有实例,您必须将 Entry 声明为 datanewtype:

newtype Entry = Entry 
    { firstName :: String 
    , lastName :: String 
    , address :: Address 
    } 

derive instance eqEntry :: Eq Entry