I have the following type:
data SomeType = Var String
deriving (Eq,Show)
newtype TypeA = TypeA [(String, SomeType)]
deriving (Eq,Show)
Also, I have a function:
fun1 :: TypeA -> TypeA -> TypeA
I can use this function for mappend
.
I don't understand, how to implement Monoid interface in my case.
If you already have fun1
, just add an instance:
instance Monoid TypeA where
mempty = .... -- fill this with the neutral element
mappend = fun1
Probably, you want mempty = TypeA []
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.