I'm teaching myself Haskell, and I've come across two implementations of a "flip" function that raise questions for me about name declaration.
These two do the same thing:
flip'' :: (a -> b -> c) -> b -> a -> c
flip'' f y x = f x y
flip' :: (a -> b -> c) -> (b -> a -> c)
flip' f = g
where g x y = f y x
The first example is as I would expect. In the second example, I'm confused why we're allowed to write g x y = f y x
when we haven't declared either x or y yet. I understand that lazy evaluation means neither is evaluated until they're needed, but I expected the compiler to at least want a declaration.
It compiles even without the type signature... this works fine:
flip' f = g
where g x y = f y x
So are x and y just completely untyped variables? Or is something else going on? Why are we able to do this?