Haskell "Non type-variable argument in the constraint"

However, I thought it would then follow that I could write:

let results = map (4) listOfPartiallyAppliedFunctions

No, if you would have performed \x -> 4 x, you could replace it with 4. But since 4 means it is a Num instance, and you likely did not make a function a -> b an instance of Num, the compiler can not solve this. The compiler thus says that it does not find a way to convert the number 4 into a function, and definitely not a function that takes as input a function Num a => a -> a, and then converts this to a b.

You can however write the above as just:

let results = map ($ 4) listOfPartiallyAppliedFunctions

Here we thus perform a sectioning of an infix operator [Haskell-wiki] on the ($) :: (a -> b) -> a -> b function.


Three "laws" of operator sections are

(a `op` b)  =  (a `op`) b  =  (`op` b) a  =  op a b

(the missing argument goes into the free slot near the operator),

or with $,

a b  =  (a $ b)  =  (a $) b  =  ($ b) a  =  ($) a b

Thus

(\ x -> x 4) = (\ x -> x $ 4) = (\ x -> ($ 4) x)

and that, by eta-reduction, is

($ 4)