Solution (source code)

= Solution

Assign $y:u$ and $x:v$. The application `s y x` forces $s:u\to v\to w$ for a fresh type $w$; applying `f` to that result forces $f:w\to r$. No further equations identify these four type variables. The <principal type> is therefore

``
k :: (u -> v -> w) -> v -> (w -> r) -> u -> r
k s x f y = f (s y x)
``

Every compatible typing is an instance of this one, because <type inference> imposed precisely the two application constraints and no class constraints.