Hi,
I'm reading "Learn You a Haskell..." and have a question about the chapter "Making Our Own Types and Typeclasses". On the 'Functor'/'Either' example, I feel completely lost. I don't see why the 'Left x' portion of 'Functor (Either a)' is simply 'Left x' and the document is not exactly clear. Any clarification would be most appreciated. Sincerely, Frank D. Martinez -- P.S.: I prefer to be reached on BitMessage at BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20140818/8fabed6e/attachment.html> |
The definition of a Functor requires that exactly one of the type variables
be free, which is why it's written as `Either a` instead of `Either a b`. Any fields that are not `b` must be simply passed through as-is by fmap. There could be a separate functor that would fmap over the Left, but there isn't (in the base package anyhow). There's a related Functor for `(,) a` where the Functor fmaps over the snd of the tuple, and the fst is left as-is. fmap (+1) ('a', 2) == ('a', 3) fmap (+1) (Right 2) == Right 3 fmap (+1) (Left 'a') == Left 'a' Chris Done recently prototyped a fmap explorer that you might find useful: http://www.reddit.com/r/haskell/comments/2dok9w/functor_explorer/ -bob On Mon, Aug 18, 2014 at 11:02 AM, Frank <frankdmartinez at gmail.com> wrote: > Hi, > I'm reading "Learn You a Haskell..." and have a question about the > chapter "Making Our Own Types and Typeclasses". On the 'Functor'/'Either' > example, I feel completely lost. I don't see why the 'Left x' portion of > 'Functor (Either a)' is simply 'Left x' and the document is not exactly > clear. Any clarification would be most appreciated. > > Sincerely, > Frank D. Martinez > > > -- > P.S.: I prefer to be reached on BitMessage at > BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6 > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20140818/d6fbfe75/attachment.html> |
Thanks!
On Monday, August 18, 2014, Bob Ippolito <bob at redivi.com> wrote: > The definition of a Functor requires that exactly one of the type > variables be free, which is why it's written as `Either a` instead of > `Either a b`. Any fields that are not `b` must be simply passed through > as-is by fmap. There could be a separate functor that would fmap over the > Left, but there isn't (in the base package anyhow). > > There's a related Functor for `(,) a` where the Functor fmaps over the snd > of the tuple, and the fst is left as-is. > > fmap (+1) ('a', 2) == ('a', 3) > fmap (+1) (Right 2) == Right 3 > fmap (+1) (Left 'a') == Left 'a' > > Chris Done recently prototyped a fmap explorer that you might find useful: > http://www.reddit.com/r/haskell/comments/2dok9w/functor_explorer/ > > -bob > > > > On Mon, Aug 18, 2014 at 11:02 AM, Frank <frankdmartinez at gmail.com > <javascript:_e(%7B%7D,'cvml','frankdmartinez at gmail.com');>> wrote: > >> Hi, >> I'm reading "Learn You a Haskell..." and have a question about the >> chapter "Making Our Own Types and Typeclasses". On the 'Functor'/'Either' >> example, I feel completely lost. I don't see why the 'Left x' portion of >> 'Functor (Either a)' is simply 'Left x' and the document is not exactly >> clear. Any clarification would be most appreciated. >> >> Sincerely, >> Frank D. Martinez >> >> >> -- >> P.S.: I prefer to be reached on BitMessage at >> BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6 >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> <javascript:_e(%7B%7D,'cvml','Beginners at haskell.org');> >> http://www.haskell.org/mailman/listinfo/beginners >> >> > -- P.S.: I prefer to be reached on BitMessage at BM-2D8txNiU7b84d2tgqvJQdgBog6A69oDAx6 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20140818/83fa38d9/attachment.html> |
Free forum by Nabble | Edit this page |