Haskell Functor implied law

后端 未结 4 1227
清酒与你
清酒与你 2021-02-07 02:49

Typeclassopedia says:

\"A similar argument also shows that any Functor instance satisfying the first law (fmap id = id) will automatically satisfy the second law as well

4条回答
  •  盖世英雄少女心
    2021-02-07 03:18

    I'd say the second law is not mentioned for validity reasons, but rather as an important property:

    The first law says that mapping the identity function over every item in a container has no effect. The second says that mapping a composition of two functions over every item in a container is the same as first mapping one function, and then mapping the other. --- Typeclassopedia

    (I can't see why this first law implies the second law, but I'm not a skilled Haskeller - its probably obvious when you know what's going on)

提交回复
热议问题