What does _
at the beginning of lines mean. Usually it is the wildcard placeholder but thinking of it that way here isn’t giving me any meaning.
i think it just means: the thing you moused over, which in this case was fmap
.
Can the general fmap with the specific type be lined-up?
I don’t think what you showed is right.
The lefthand fmap
, when lined up is:
(a -> b). -> ( f a -> f b)
Maybe [Integer] Maybe Integer ( [Integer] -> Maybe [Integer]) ([Integer] -> Maybe Integer )
Your second screenshot is correct for the righthand fmap
. I see your confusion, which is that it looks like f (g a)
, because both Maybe
and []
are functors. But the crucial point is that a
can be anything! In this case, a
is [Integer]
and b
is Integer
. So it’s indeed f a
.
Could you shed some light on…
Yeah, it’s a more verbose way of writing things. In haskell, as you know, you can write universally quantified types like id :: a -> a
, but you can also more explicitly write id :: forall a. a -> a
. You can even explicitly specify the kind, as in: id :: forall (a :: *). a -> a
. (This is more common in more recent GHC version, like 9).
In the type of fmap
, which is, in full verbosity:
fmap :: forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
you can read this as saying: for any three types f
, a
, and b
, such that f
has kind * -> *
, and also such that f
is an instance of the Functor
class, fmap
takes a function a -> b
and gives you a function f a -> f b
.
Addendum
Rather than the lining up, which is a bit hard to typeset, let me also use the following notation:
For the righthand fmap
:
a ~ [Integer]
b ~ Integer
f ~ Maybe
(f a) ~ Maybe [Integer]
(f b) ~ Maybe Integer
For the lefthand fmap
:
a ~ Maybe [Integer]
b ~ Maybe Integer
f ~ ( (->) [Integer]
(f a) ~ ([Integer] -> Maybe [Integer])
(f b) ~ ([Integer] -> Maybe Integer)
Hopefully that’s totally clear and non-ambiguous - let me know if not.