|
Because you write functions like this in mathematics as well. What we usually see is something like this: f(x) = y
But if you look at it carefully the function f is a mapping of the domain x to the range y (the arrow is f), written like so: x -> y
Of course, the domain, being a set of all permissible values, is the type. So we write the type instead: type1 -> type2
Everything in Haskell is a function, and pure functions only ever take ONE parameter. Therefore the commas make no sense. The name in front just aids in naming stuff.If you have a function that takes 2 parameters, they'd have to be curried. How would you represent curried functions? f::type1 -> type2 -> type3
To make it more concrete, let's look at add instead of f.So we can define a function like this (let's use Python for its readability): def add(a, b): return a + b
But remember, in haskell, functions are pure. Meaning they only map one input to one output. In order to make this happen, we need to split the function up into parts that only take one parameter.Let's start with the plus operator as a function (it is one in Haskell just made into an infix). To think about it, it'd be something like this: plus(a)(b)
Where plus(a) is defined as: def plus(a): return plusA
Hence the first part would become a curried function like so, which takes another parameter: plusA(b)
Where plusA() is defined as such: def plusA(b): return b + a # a is a constant
So if you look at it from the types it was being transformed from: plus() # takes a Real, returns plusA.
plusA(___) # takes a Real, returns a Real. written as (Real -> Real)
So if you put it together, the function signature for plus() is:plus() takes Real - plus :: Real->
plus() returns plusA (which is Real->Real) - plus :: Real-> (Real-> Real)
Or in other words we can write it as such add :: Real -> Real -> Real
|
fun1 would take a function and return a function, whereas fun2 takes an A and returns a curried function of B,C -> D.