2 ms·
Thanks to ncd for clarifying, here are my own comments too. When you write f: Int -> Int -> Int f a b = a + b the compiler (at least in Haskell) creat
by bo1024 10y ago
Thanks to ncd for clarifying, here are my own comments too. When you write
f: Int -> Int -> Int
f a b = a + b
the compiler (at least in Haskell) creates f as a function that takes a single argument, a, and outputs a function. That outputted function takes a single argument, b and outputs an Int.
When you apply the function f:
f 5 7
what's really happening here is that f is first applied to 5. This creates a new function, call it g, taking in a single integer and outputting that integer plus 5. Then, this new function is applied to 7. (The compiler may optimize a lot of this away, but that is how you should think of what's happening in my opinion.)
Hope that helps!
- bo1024 10y agoI guess this comes back full circle to the original point: you should think of everything being left-associative here, so by default the above is interpreted as f: Int -> (Int -> Int) ... (f 5) 7