Take this expression (where both p
must have the same type, because the lambda variable cannot have two types at the same time, unless you explicitly specify the polymorphic type):
p 1 p
What is type p
in this context? Say 1
is an Int
for simplicity. Start with a simple try:
(p :: Int -> ? -> Int) 1 p
So what is the question mark? Well, it must be type p
, because the argument you give. So:
(p :: Int -> (Int -> ? -> Int) -> Int) 1 p
Again, the same problem, the same solution:
(p :: Int -> (Int -> (Int -> ? -> Int) -> Int) -> Int) 1 p
Now you understand why we have a problem with infinite types: although we do not need to know the type of the second argument p
; because a system like Haskell is strict (aka not lazy), it still needs to know the type and focus on this infinite type.
This code succeeds:
(\xy -> 1) 1 p
... because the function on the left can have a different type from p
, because they are different functions, so we are not trying to combine these types:
((\ xy -> 1) :: a -> b -> Int) 1 (p :: c -> d -> Int)
source share