繁体   English   中英

如何为我的类型制作Monoid实例?

[英]How to make Monoid instance for my type?

我有以下类型:

data SomeType = Var String
    deriving (Eq,Show)

newtype TypeA = TypeA [(String, SomeType)]
  deriving (Eq,Show)

另外,我有一个功能:

fun1 :: TypeA -> TypeA -> TypeA

我可以将此功能用于mappend

我不明白如何在我的情况下实现Monoid接口。

如果您已经拥有fun1 ,只需添加一个实例:

instance Monoid TypeA where
   mempty = .... -- fill this with the neutral element
   mappend = fun1

可能您想要mempty = TypeA []

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM