Recently I have been learning about compositions in haskell and am now a bit confused concerning this example.
(const . min) 3 0 4
As a result I get 3, so internally it must be computed like:
const (min 3) 0 4
But I thought since min takes two arguments, it should look like this:
const (min 3 0) 4
So apparently the composition only takes this one argument, in this case 3, instead of all the arguments for min like I expected it to. Does that mean compositions only take one argument per default or what am I not getting here?
min 3 0applies the (1-arg) functionminto argument3. The result is a (1-arg) function, that is then applied to0. The result of that is the number0. We of course like to considerminas a 2-arg function, but technically there's no such a thing in Haskell. Coherently, composition composes two (1-arg) functions. To compose "2-arg" functions (i.e., 1-arg returning 1-arg functions) one would need some other operator, or simply use a lambda. - chi