I have following declaration:
data Two a b = Two a b deriving (Eq, Show)
instance (Semigroup a, Semigroup b) => Semigroup (Two a b) where
(Two a b) <> (Two c d) = Two (a <> c) (b <> d)
And tried it in the prelude:
*Main First Lib MonoidLaws Semi> (Two a b) <> (Two c d) = Two (a <> c) (b <> d)
<interactive>:10:3: error:
* Occurs check: cannot construct the infinite type: t1 ~ Two t1 t1
Expected type: t1 -> t -> b
Actual type: Two t1 t1 -> Two t t -> Two b b
* Relevant bindings include
(<>) :: t1 -> t -> b (bound at <interactive>:10:3)
How can I use mappend
function from Semigroup
for Two
datatype in prelude?
a
andb
in the repl?Two a b <> Two c d = Two (a <> c) (b <> d)
in the REPL? That's a declaration, i.e. you define a new<>
operator there (which is not connected to the one from theSemigroup
class). Why?