
The function g, when called with a binary function returns a type error which I’d really like to understand: why is this type “infinite" rather than just incomplete or something similar? I would have expected some kind of partial binding. Can someone help me with an explanation? Prelude> let f g = g . g Prelude> let sum x y = x + y Prelude> f sum <interactive>:14:3: Occurs check: cannot construct the infinite type: a ~ a -> a Expected type: (a -> a) -> a -> a Actual type: a -> a -> a Relevant bindings include it :: (a -> a) -> a -> a (bound at <interactive>:14:1) In the first argument of ‘f’, namely ‘sum’ In the expression: f sum With a similar call using lambda expressions, the error is different: Prelude> (\x y -> x + y) . (\x y -> x + y) <interactive>:32:1: Non type-variable argument in the constraint: Num (a -> a) (Use FlexibleContexts to permit this) When checking that ‘it’ has the inferred type it :: forall a. (Num a, Num (a -> a)) => a -> (a -> a) -> a -> a Prelude>