Skip to content

fmap with a function

What is this code doing?

repl example
> func = fmap not (\x -> x > 3) 
> func 2
True
> func 4 
False

Answer

fmap is the method of the Functor typeclass.

To understand what fmap does whenever it is called, it is necessary to know which instance of fmap is being used. You can find this out by mousing over fmap (first place the line func = fmap not (\x -> x > 3) in a Haskell file in your project), to see:

Functor

The line $dFunctor :: Functor ((->) Integer) means that the instance of Functor being used is ((->) Integer).

Tip

If it is unclear what ((->) Integer) means, see here and here.

The instance of Functor for ((->) Integer) is:

instance Functor ((->) r) where
    fmap f g = f . g -- (1)! 
  1. Or in pointfree style: fmap = (.)

and this is what is being used in the examples above.

Comments