I'm currently studying semigroups and trying to figure out how to determine which type variables need a semigroup instance. Here are a couple of examples from Evan Cameron's github (https://github.com/leshow/haskell-programming-book/blob/ ):master/src/Ch15ex.hs (1)data Validation a b= Failure a| Success bderiving (Eq, Show)instance Semigroup a => Semigroup (Validation a b) whereSuccess a <> Success b = Success aFailure a <> Success b = Success bSuccess a <> Failure b = Success aFailure a <> Failure b = Failure (a <> b)* Why doesn't 'b' need an instance of semigroup?(2)newtype AccumulateRight a b = AccumulateRight (Validation a b) deriving (Eq, Show)instance Semigroup b => Semigroup (AccumulateRight a b) whereAccumulateRight (Success a) <>AccumulateRight (Failure b) =AccumulateRight (Success a)AccumulateRight (Failure a) <>AccumulateRight (Success b) =AccumulateRight (Success b)AccumulateRight (Failure a) <>AccumulateRight (Failure b) =AccumulateRight (Failure a)
AccumulateRight (Success a) <> AccumulateRight (Success b) = AccumulateRight (Success (a <> b))
* Why doesn't 'a' need an instance of semigroup?
Thank you,
AndreaSent with ProtonMail Secure Email.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners