Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下类型:
data SomeType = Var String deriving (Eq,Show) newtype TypeA = TypeA [(String, SomeType)] deriving (Eq,Show)
另外,我有一个功能:
fun1 :: TypeA -> TypeA -> TypeA
我可以将此功能用于mappend.
mappend
我不明白,在我的情况下如何实现 Monoid 接口。
如果您已经拥有fun1,只需添加一个实例:
fun1
instance Monoid TypeA where mempty = .... -- fill this with the neutral element mappend = fun1
可能,你想要mempty = TypeA [].
mempty = TypeA []