<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 14, 2015 at 11:47 AM, Shishir Srivastava <span dir="ltr"><<a href="mailto:shishir.srivastava@gmail.com" target="_blank">shishir.srivastava@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Hi, </div><div><br></div><div>Can someone please explain the difference in outputs of the following two expressions - </div><div><br></div><div>--------------</div><div><br></div><div><div><font face="monospace, monospace">ghci> fmap (replicate 3) (Right "blah")  </font></div><div><font face="monospace, monospace">Right ["blah","blah","blah"]  </font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">ghci> fmap (replicate 3) (Left "foo")  </font></div><div><font face="monospace, monospace">Left "foo" </font></div></div><div><font face="monospace, monospace"><br></font></div><div>---------------</div><div><br></div><div>Why does 'Right' return a list of Strings whereas 'Left' returns just a String.</div></div></blockquote><div><br></div><div>Because that's the way Either was made an instance of fmap. It's defined so that fmap _ (Left x) = Left x, but fmap f (Right y) = Right (f y).</div><div><br></div><div>The docs say:</div><div><br></div><div><div>The 'Either' type is sometimes used to represent a value which is</div><div>either correct or an error; by convention, the 'Left' constructor is</div><div>used to hold an error value and the 'Right' constructor is used to</div><div>hold a correct value (mnemonic: \"right\" also means \"correct\").</div></div><div><br></div></div></div></div>