Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <$> mean in Haskell?

Tags:

haskell

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.

like image 917
prometheus21 Avatar asked May 17 '16 21:05

prometheus21


People also ask

What does >>= mean in Haskell?

Essentially, a >> b can be read like "do a then do b , and return the result of b ". It's similar to the more common bind operator >>= .

What does AT symbol mean in Haskell?

The @ Symbol is used to both give a name to a parameter and match that parameter against a pattern that follows the @ . It's not specific to lists and can also be used with other data structures.

What do colons mean in Haskell?

In Haskell, the colon operator is used to create lists (we'll talk more about this soon). This right-hand side says that the value of makeList is the element 1 stuck on to the beginning of the value of makeList .

What does == mean in Haskell?

The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.


1 Answers

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.

like image 165
leftaroundabout Avatar answered Sep 22 '22 16:09

leftaroundabout