<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">15 квіт. 2015 19:27 "emacstheviking" <<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>> пише:<div><div class="h5"><br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I just love the way Haskell can blow something really simple into something truly mind blowingly obtuse looking at times!<div>It's no wonder Haskell won't be "mainstream" for a while yet, but that's fine, it means the rest of us can charge better rates for now.</div><div dir="ltr">:)<br></div></div><br></blockquote></div></div></div></blockquote></div><br></div><div class="gmail_extra">This is simple. More precisely, it couldn't be otherwise.<br><br><div style="margin-left:40px">data Either l r = Left l | Right r<br></div><br></div><div class="gmail_extra">See how this definition has two type parameters ? The problem was obscured in the first question by the fact that "replicate 3" can be applied to any type. But if you take a less polymorphic function like length, it soon become obvious that this is the way fmap should work :<br><br><div style="margin-left:40px">fmap length (Right "stuff") = length "stuff"<br></div><div style="margin-left:40px">fmap length (Left 5)          = length 5 ???? What does that even means ?<br></div><br></div><div class="gmail_extra">Since the type contained by Left and Right are different, you can't in general apply the same function to both possibilities. Now the right type is the last one to occur in "Either left right" so it's the one that's abstracted over in the Functor instance, there is no Functor instance for Either, the instance is for "Either left" with the left type fixed, fmap don't touch the left type, so it can't do anything to a "Left x" value.<br><br></div><div class="gmail_extra">Semantically, "Either left right" can be seen as a container of one or zero "right" that contains out-of-band information of type "left" when it's empty. So when you fmap over it, you only touch the content, not the out-of-band information.<br><br>-- <br></div><div class="gmail_extra">Jedaï<br></div></div>