[Haskell-beginners] Left vs Right

Chas Leichner chas at chas.io
Tue Apr 14 16:58:16 UTC 2015


This is meant to model errors. You want your computation to continue if
everything is going all-Right, but if there is an error, you want it to
stop there are report the error. This error is represented by Left
constructor.

On Tue, Apr 14, 2015 at 9:56 AM, Bob Ippolito <bob at redivi.com> wrote:

> 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
>>
>>
>
> _______________________________________________
> 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/96a64453/attachment.html>


More information about the Beginners mailing list