I try to solve the exercises from the haskellbook and created following module:
module Exercises where
import Data.Semigroup
import Data.Monoid
import Test.QuickCheck
data Trivial = Trivial deriving (Eq, Show)
instance Semigroup Trivial where
_ <> _ = Trivial
instance Monoid Trivial where
mempty = Trivial
mappend x y = x <> y
And the compiler complains:
file: 'file:///d%3A/haskell/chapter15/src/Exercises.hs'
severity: 'Error'
message: 'Ambiguous occurrence `<>'
It could refer to either `Data.Semigroup.<>',
imported from `Data.Semigroup' at src\Exercises.hs:3:1-21
or `Data.Monoid.<>',
imported from `Data.Monoid' at src\Exercises.hs:4:1-18'
at: '14,19'
source: ''
How to solve the problem?
mappend x y = Data.Monoid.<> x y
work? – 9000Data.Monoid
imported? All it really brings into scope that isn't already in the Prelude is a bunch of newtypes and its version of<>
. – AlecSemigroup
will be a superclass ofMonoid
. – dfeuer