I\'m trying to do one of the Semigroup exercises in Haskell Book (Chapter 15, \"Monoid, Semigroup\") but I\'m stuck. The following is given:
newtype Combine
You can shadow Monoid
's (<>)
this way:
import Data.Monoid hiding ((<>))
Then when you import Data.Semigroup
, you will have just one (<>)
in scope: the one from Data.Semigroup
.
What they want is probably the addition of functions. For that, type b
needs to be a Semigroup :
import Data.Semigroup
newtype Combine a b =
Combine { unCombine :: (a -> b) }
instance Semigroup b => Semigroup (Combine a b) where
(Combine f) <> (Combine g) = Combine (\x -> f x <> g x)