[Haskell-beginners] Left vs Right

emacstheviking objitsu at gmail.com
Thu Apr 16 08:41:29 UTC 2015


"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."

Yup. Whatever he said. ;)  ...that's bordering on monadic comparison
tutorials if you ask me... LOL. A lot of people may not even know what "in
band" and "out-of-band" even means. I grew up with X25, RS232, HDLC etc so
that's ok by me. You have to be very very careful about how you explain
things to  people. One of my favourite videos on YouTube is some guy asking
Richard Feynman how magnets work...well, he did ask!
https://www.youtube.com/watch?v=wMFPe-DwULM



On 15 April 2015 at 20:39, Chaddaï Fouché <chaddai.fouche at gmail.com> wrote:

> 15 квіт. 2015 19:27 "emacstheviking" <objitsu at gmail.com> пише:
>>
>> I just love the way Haskell can blow something really simple into
>>> something truly mind blowingly obtuse looking at times!
>>> 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.
>>> :)
>>>
>>>
> This is simple. More precisely, it couldn't be otherwise.
>
> data Either l r = Left l | Right r
>
> 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 :
>
> fmap length (Right "stuff") = length "stuff"
> fmap length (Left 5)          = length 5 ???? What does that even means ?
>
> 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.
>
> 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.
>
> --
> Jedaï
>
> _______________________________________________
> 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/20150416/98bab247/attachment-0001.html>


More information about the Beginners mailing list