haskell - What does the 'f' represent in the fmap function of a functor? -
i'm looking @ following function:
fmap :: (a -> b) -> f -> f b
and want understand 'f' is, in (f a
or f b
). article reading describes 'box' what's actual correct name it? type variable? think i'm confusing , thinking it's function application - correct?
your intuition kind of function application correct, not regular functions. instead, application of type constructors on type level.
specifically, functors must have kind (type-of-type) * -> *
means take 1 type argument , produce concrete type *
such as, example, [int]
.
examples of such type constructors include io, maybe, [], either e
, many others, , these specific examples have valid functor instances.
fmap (+1) [1,2,3] :: [] int -- known [int] = [2,3,4] fmap (+1) (just 1) :: maybe int = 2 fmap (+1) (right 1) :: either e int = right 2 fmap (+1) (return 1) :: io int -- uses monad io instance "=" 2