What does <$> mean in Haskell?

后端 未结 1 736
天命终不由人
天命终不由人 2020-12-24 10:53

While reading a piece of Haskell code I came upon this: <$>. What does it mean in Haskell? After some google searches I remain in the dark.

相关标签:
1条回答
  • 2020-12-24 11:16

    Google is not the best search engine for Haskell. Try Hoogle or Hayoo, both will point you right away to this:

    (<$>) :: Functor f => (a->b) -> f a -> f b
    

    It's merely an infix synonym for fmap, so you can write e.g.

    Prelude> (*2) <$> [1..3]
    [2,4,6]
    Prelude> show <$> Just 11
    Just "11"
    

    Like most infix functions, it is not built-in syntax, just a function definition. But functors are such a fundamental tool that <$> is found pretty much everywhere.


    Hayoo has been offline for quite a while now.

    0 讨论(0)
提交回复
热议问题