I was told that every function in Haskell can have only one formal parameter, and defining a function with multiple parameters is just a syntactic sugar. Does that mean a multi-parameter function can be desugared into a nested lambda expression without losing or gaining any property?
I assumed that the answer would be yes. When I actually tried with the two functions below, however, I encountered something that looks mysterious to noob's eyes.
-- aFile.hs
f x y = x + y
g = \x -> \y -> x + y
I defined f and g in a file both without type annotations, expecting the type of both functions will be Num a => a -> a -> a. The actual result, however, was puzzling:
Prelude> :load aFile.hs
Ok, modules loaded: Main.
*Main> :type f
f :: Num a => a -> a -> a
*Main> :type g
g :: Integer -> Integer -> Integer
*Main> let h = \x -> \y -> x + y
*Main> :type h
h :: Num a => a -> a -> a
Somehow g is not polymorphic. On what ground Integer is inferred here? Does this result mean that the multi-parameter function definition is not a syntactic sugar?
Even more confusingly, h, which is the same as g but entered directly into the REPL, has the expected polymorphic type. How come g and h are different?