I am trying to learn haskell and could not configure it out, why following code snippet can not get compiled:
*Uncurry> applyTwice f x = f f x <interactive>:14:20: error: • Occurs check: cannot construct the infinite type: t ~ t -> t2 -> t1 • In the first argument of ‘f’, namely ‘f’ In the expression: f f x In an equation for ‘applyTwice’: applyTwice f x = f f x • Relevant bindings include x :: t2 (bound at <interactive>:14:14) f :: t -> t2 -> t1 (bound at <interactive>:14:12) applyTwice :: (t -> t2 -> t1) -> t2 -> t1 (bound at <interactive>:14:1)
This would be fine:
applyTwice f x = f (f x)
In haskell function application is left associative, the first code snippet would be apply like:
(f f) x
(f f) x it is wrong?