[Haskell-beginners] Left vs Right

Bob Ippolito bob at redivi.com
Tue Apr 14 16:56:48 UTC 2015


The Functor instance is defined for `Either a`, so Left is fixed. fmap only
maps over Right. You'll find the same behavior for `(,) a`, e.g. `fmap (*2)
(1,2) == (1,4)`.

On Tue, Apr 14, 2015 at 9:47 AM, Shishir Srivastava <
shishir.srivastava at gmail.com> wrote:

> Hi,
>
> Can someone please explain the difference in outputs of the following two
> expressions -
>
> --------------
>
> ghci> fmap (replicate 3) (Right "blah")
> Right ["blah","blah","blah"]
>
> ghci> fmap (replicate 3) (Left "foo")
> Left "foo"
>
> ---------------
>
> Why does 'Right' return a list of Strings whereas 'Left' returns just a
> String.
>
> Thanks,
> Shishir
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150414/0cc1a447/attachment.html>


More information about the Beginners mailing list