<div>Thank you Theodore. Yes, changing the variable names makes it clearer. Also the fact that only failures are combined on the right hand side...<br></div><div><br></div><div>Regards,<br></div><div>Andrea<br></div><div><br></div><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><blockquote type="cite" class="protonmail_quote"><div>-------- Original Message --------<br></div><div>Subject: Re: [Haskell-beginners] Semigroup Instances<br></div><div>Local Time: February 6, 2017 5:56 PM<br></div><div>UTC Time: February 6, 2017 11:56 PM<br></div><div>From: tanuki@gmail.com<br></div><div>To: Atrudyjane <atrudyjane@protonmail.com>, The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org><br></div><div><br></div><div dir="ltr"><div>Gmail put you in spam.<br></div><div><br></div><div>If you haven't figured this out since you asked -- it's a matter of confusing (IMO bad) variable names. Check the data definition:<br></div><div><br></div><div><span class="font" style="font-family:monospace, monospace">data Validation a b<br>  = Failure a<br>  | Success b<br>  deriving (Eq, Show)</span></div><div><br></div><div>Failures are always type <span class="font" style="font-family:monospace, monospace">a</span>, and successes are always type <span class="font" style="font-family:monospace, monospace">b</span>. The type variables used in the first line correspond to these. But in the definitions of <span class="font" style="font-family:monospace, monospace">(<>)</span>, they are just local values. The instance could be rewritten like so:<br></div><div><br></div><div><span class="font" style="font-family:monospace, monospace"><span class="size" style="font-size:12.8px">instance Semigroup a => Semigroup (Validation a b) where</span></span><br></div><div><div style="font-size:12.8px"><span class="font" style="font-family:monospace, monospace">  Success x <> Success y = Success x</span><br></div><div style="font-size:12.8px"><span class="font" style="font-family:monospace, monospace">  Failure x <> Success y = Success y</span><br></div><div style="font-size:12.8px"><span class="font" style="font-family:monospace, monospace">  Success x <> Failure y = Success x</span><br></div><div style="font-size:12.8px"><span class="font" style="font-family:monospace, monospace">  Failure x <> Failure y = Failure (x <> y)</span><br></div></div></div><div class="gmail_extra"><div><br></div><div class="gmail_quote"><div>On Thu, Jan 26, 2017 at 1:55 PM, Atrudyjane <span dir="ltr"><<a rel="noreferrer nofollow noopener" href="mailto:atrudyjane@protonmail.com">atrudyjane@protonmail.com</a>></span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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 rel="noreferrer nofollow noopener" href="https://github.com/leshow/haskell-programming-book/blob/master/src/Ch15ex.hs">https://github.com/leshow/<wbr>haskell-programming-book/blob/<wbr>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="m_-6963159195776523985pl-k">ewtype</span> <span class="m_-6963159195776523985pl-en">AccumulateRight</span> <span class="m_-6963159195776523985pl-smi">a</span> <span class="m_-6963159195776523985pl-smi">b</span> <span class="m_-6963159195776523985pl-k">=</span> <span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-en">Validation</span> <span class="m_-6963159195776523985pl-smi">a</span> <span class="m_-6963159195776523985pl-smi">b</span>) <span class="m_-6963159195776523985pl-k">deriving</span> (<span class="m_-6963159195776523985pl-e">Eq</span>, <span class="m_-6963159195776523985pl-e">Show</span>)<br></div><div><br></div><div><span class="m_-6963159195776523985pl-k">instance</span> <span class="m_-6963159195776523985pl-en">Semigroup</span> <span class="m_-6963159195776523985pl-smi">b</span> <span class="m_-6963159195776523985pl-k">=></span> <span class="m_-6963159195776523985pl-en">Semigroup</span> (<span class="m_-6963159195776523985pl-en">AccumulateRight</span> <span class="m_-6963159195776523985pl-smi">a</span> <span class="m_-6963159195776523985pl-smi">b</span>) <span class="m_-6963159195776523985pl-k">where</span><br></div><div><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> a) <span class="m_-6963159195776523985pl-k"><></span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Failure</span> b) <span class="m_-6963159195776523985pl-k">=</span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> a)<br></div><div><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Failure</span> a) <span class="m_-6963159195776523985pl-k"><></span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> b) <span class="m_-6963159195776523985pl-k">=</span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> b)<br></div><div><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Failure</span> a) <span class="m_-6963159195776523985pl-k"><></span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Failure</span> b) <span class="m_-6963159195776523985pl-k">=</span><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Failure</span> a)<br></div><div><br></div><br><table class="m_-6963159195776523985highlight m_-6963159195776523985tab-size m_-6963159195776523985js-file-line-container"><tbody><tr><td class="m_-6963159195776523985blob-code m_-6963159195776523985blob-code-inner m_-6963159195776523985js-file-line"><div><span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> a) <span class="m_-6963159195776523985pl-k"><></span> <span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> b) <span class="m_-6963159195776523985pl-k">=</span> <span class="m_-6963159195776523985pl-ent">AccumulateRight</span> (<span class="m_-6963159195776523985pl-ent">Success</span> (a <span class="m_-6963159195776523985pl-k"><></span> b)) <br></div><div><br></div><div>* Why doesn't 'a' need an instance of semigroup?<br></div><div><br></div><div><br></div><div>Thank you,<br></div><div>Andrea<br></div></td></tr><tr></tr></tbody></table><div class="m_-6963159195776523985protonmail_signature_block"><div class="m_-6963159195776523985protonmail_signature_block-user"><br></div><div class="m_-6963159195776523985protonmail_signature_block-proton">Sent with <a rel="noreferrer nofollow noopener" href="https://protonmail.com">ProtonMail</a> Secure Email.<br></div></div><div><br></div><div><br></div><div>______________________________<wbr>_________________<br></div><div> Beginners mailing list<br></div><div> <a rel="noreferrer nofollow noopener" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br></div><div> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer nofollow noopener">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br></div><div> <br></div></blockquote></div></div></blockquote><div><br></div>