I'm not sure why this type alias was introduced -- good reason to go back to that book! :)
However, the meaning is simple. Const
is something with two type parameters where the second type parameter doesn't matter. I'd expect it to be used somewhere that expects a type constructor with two type parameters, but, as it happens, it is not.
The expression ({ type f[x] = Const[M, x] })#f
is known as a type lambda, and it is used here (and in most places, as a matter of fact) to convert something that takes two type parameters, Const
, into something that takes one type parameter!
Now, the interesting thing is that the type parameter being received is ignored, due to its position in Const
, and, instead, M
, which is a type parameter of the monoidApplicative
definition, is used.
Note that Applicative
expects something that takes a type parameter, and here we are working with an M
where Monoid[M]
exists. Two examples of such M
would be Int
and String
, neither of which has a type parameter.
So, in a sense, we are cheating Applicative
by a trick where the type parameter is ignored and the final type gets replaced by whatever you want, so you could have an Applicative[Int]
, so to speak, despite Int
not having a type parameter.