Time for some Haskell. The following expression evaluates to Just 6
:
1


So does this one:
1


How does the second one work? How do the type signatures line up?
First consider fmap . fmap
:
1 2 3 4 5 6 7 8 9 10 11 

Then sum
:
1


Now apply fmap . fmap
to sum
:
1 2 3 4 5 

Next, the tricky bit.
Note that (a > b) ~ ((>) a b)
.
So the signature of Just
, which we’d usually write:
1


can also be expressed as:
1


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 a
.
((>) (t b))
, therefore, has a Functor instance.
If we replace f1
with ((>) (t b))
, we produce a more specific type signature, expressing a specialization of (fmap . fmap) sum
1 2 

We can further specialize it by replacing f
with Maybe.
1 2 

Now consider a specialization of Just
where a ~ (t b)
1


If we apply the specialized (fmap . fmap) sum
to this specialization of Just
, we get:
1


which can be rewritten idiomatically as:
1


This leaves us with:
1

