Time for some Haskell. The following expression evaluates to
So does this one:
How does the second one work? How do the type signatures line up?
fmap . fmap:
1 2 3 4 5 6 7 8 9 10 11
fmap . fmap to
1 2 3 4 5
Next, the tricky bit.
(a -> b) ~ ((->) a b).
So the signature of
Just, which we’d usually write:
can also be expressed as:
We want the type signature for
(fmap . fmap) sum Just.
Consider the signature of
(fmap . fmap) sum.
1 2 3 4
f1 must have a Functor instance.
((->) a) has a Functor instance for all
((->) (t b)), therefore, has a Functor instance.
If we replace
((->) (t b)), we produce a more specific type signature, expressing a specialization of
(fmap . fmap) sum
We can further specialize it by replacing
f with Maybe.
Now consider a specialization of
a ~ (t b)
If we apply the specialized
(fmap . fmap) sum to this specialization of
Just, we get:
which can be rewritten idiomatically as:
This leaves us with: