What's the point of map in Haskell, when there is fmap?

后端 未结 3 1938
遇见更好的自我
遇见更好的自我 2020-12-04 11:06

Everywhere I\'ve tried using map, fmap has worked as well. Why did the creators of Haskell feel the need for a map function? Couldn\'t

3条回答
  •  余生分开走
    2020-12-04 11:45

    Quoting from the Functor documentation at https://wiki.haskell.org/Typeclassopedia#Functor

    You might ask why we need a separate map function. Why not just do away with the current list-only map function, and rename fmap to map instead? Well, that’s a good question. The usual argument is that someone just learning Haskell, when using map incorrectly, would much rather see an error about lists than about Functor.

提交回复
热议问题