94

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.

3

1 Answer 1

129

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.

4
  • 75
    The top result for "Haskell <$>" on Google is now this page, so in a sense, Google is now a perfectly good search engine in this case! Commented Nov 19, 2018 at 16:05
  • 17
    I like that you used the dagger symbol to denote that Hayoo has been dead for some time.
    – dryairship
    Commented May 9, 2020 at 18:46
  • 2
    Why <$> instead of just `fmap`? Backticks make things infix, and it's easier to read
    – Richard
    Commented Aug 14, 2022 at 17:39
  • 5
    @Richard there's certainly a point to be made that Haskellers tend to get a bit silly with all those hieroglyphic infix operators. However, <$> is so extremely common that one quickly gets the hang of it, it fits mnemonically together with the also very common $, and it is a bit more compact and visually lean than ‌`fmap`‌. I disagree the latter is easier to read in larger contexts. Commented Aug 14, 2022 at 21:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.