Understanding how Either is an instance of Functor

后端 未结 4 1350
暖寄归人
暖寄归人 2021-02-01 02:11

In my free time I\'m learning Haskell, so this is a beginner question.

In my readings I came across an example illustrating how Either a is made an instance

4条回答
  •  离开以前
    2021-02-01 02:21

    This is right. There is also another quite important reason for this behavior: You can think of Either a b as a computation, that may succeed and return b or fail with an error message a. (This is also, how the monad instance works). So it's only natural, that the functor instance won't touch the Left values, since you want to map over the computation, if it fails, there's nothing to manipulate.

提交回复
热议问题