Haskell Language Type Application Order of parameters


Example

The problem with type arguments being implicit becomes obvious once we have more than one. Which order do they come in?

const :: a -> b -> a

Does writing const @Int mean a is equal to Int, or is it b? In case we explicitly state the type parameters using a forall like const :: forall a b. a -> b -> a then the order is as written: a, then b.

If we don't, then the order of variables is from left to right. The first variable to be mentioned is the first type parameter, the second is the second type parameter and so on.

What if we want to specify the second type variable, but not the first? We can use a wildcard for the first variable like this

const @_ @Int

The type of this expression is

const @_ @Int :: a -> Int -> a