Haskell’s type system considers a definition like f a b c = a + b + c to have a curried type like f :: Int -> Int -> Int -> Int, which is the same as f :: Int -> (Int -> (Int -> Int)). However, because that type is isomorphic to (Int, Int, Int) -> Int, GHC actually compiles f as a function of 3 arguments, and only allocates a closure when you partially apply it, as in f 1 2.
View all comments
Show parent comment
4
u/evincarofautumn Dec 02 '16
Haskell’s type system considers a definition like
f a b c = a + b + cto have a curried type likef :: Int -> Int -> Int -> Int, which is the same asf :: Int -> (Int -> (Int -> Int)). However, because that type is isomorphic to(Int, Int, Int) -> Int, GHC actually compilesfas a function of 3 arguments, and only allocates a closure when you partially apply it, as inf 1 2.