<div>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 (<a href="https://github.com/leshow/haskell-programming-book/blob/master/src/Ch15ex.hs">https://github.com/leshow/haskell-programming-book/blob/master/src/Ch15ex.hs</a>):<br></div><div>(1)<br></div><div>data Validation a b<br></div><div>  = Failure a<br></div><div>    | Success b<br></div><div>    deriving (Eq, Show)<br></div><div><br></div><div>instance Semigroup a => Semigroup (Validation a b) where<br></div><div>  Success a <> Success b = Success a<br></div><div>   Failure a <> Success b = Success b<br></div><div>   Success a <> Failure b = Success a<br></div><div>   Failure a <> Failure b = Failure (a <> b)<br></div><div><br></div><div>* Why doesn't 'b' need an instance of semigroup?<br></div><div>(2)<br></div><div>n<span class="pl-k">ewtype</span> <span class="pl-en">AccumulateRight</span> <span class="pl-smi">a</span> <span class="pl-smi">b</span> <span class="pl-k">=</span> <span class="pl-ent">AccumulateRight</span> (<span class="pl-en">Validation</span> <span class="pl-smi">a</span> <span class="pl-smi">b</span>) <span class="pl-k">deriving</span> (<span class="pl-e">Eq</span>, <span class="pl-e">Show</span>)<br></div><div><br></div><div><span class="pl-k">instance</span> <span class="pl-en">Semigroup</span> <span class="pl-smi">b</span> <span class="pl-k">=></span> <span class="pl-en">Semigroup</span> (<span class="pl-en">AccumulateRight</span> <span class="pl-smi">a</span> <span class="pl-smi">b</span>) <span class="pl-k">where</span><br></div><div><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> a) <span class="pl-k"><></span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Failure</span> b) <span class="pl-k">=</span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> a)<br></div><div><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Failure</span> a) <span class="pl-k"><></span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> b) <span class="pl-k">=</span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> b)<br></div><div><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Failure</span> a) <span class="pl-k"><></span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Failure</span> b) <span class="pl-k">=</span><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Failure</span> a)<br></div><br><table class="highlight tab-size js-file-line-container" data-tab-size="4"><tbody><tr><td id="LC217" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> a) <span class="pl-k"><></span> <span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> b) <span class="pl-k">=</span> <span class="pl-ent">AccumulateRight</span> (<span class="pl-ent">Success</span> (a <span class="pl-k"><></span> b)) <br><br>* Why doesn't 'a' need an instance of semigroup?<br><br><br>Thank you,<br>Andrea<br><br></td></tr><tr></tr></tbody></table><div class="protonmail_signature_block "><div class="protonmail_signature_block-user "><br></div><div class="protonmail_signature_block-proton ">Sent with <a href="https://protonmail.com">ProtonMail</a> Secure Email.<br></div></div><div><br></div>