Is it possible to define my own ++ operator for a custom data type in Haskell?
I have:
data MyType = MyType [String]
and I would like to define my own concatenation operator as:
instance ? MyType where
(MyType x) ++ (MyType y) = MyType (x ++ y)
I can’t seem to find the name of the instance class anywhere.
If you don’t insist on calling the operator
(++),Then you can use
which is an alias for
mappend(I thought it was already a type class member, but it isn’t :/). Lists hava aMonoidinstance wheremappendis(++), so that would do what you desire. TheMonoidinstance also gives youwhich you can use to concatenate a list of
MyTypes.