What does <$> mean in Haskell?

Haskell

Haskell Problem Overview


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.

Haskell Solutions


Solution 1 - Haskell

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionprometheus21View Question on Stackoverflow
Solution 1 - HaskellleftaroundaboutView Answer on Stackoverflow