views:

102

answers:

1

In the example given in http://web.archive.org/web/20080622204226/http://www.cs.vu.nl/boilerplate/

-- Increase salary by percentage
increase :: Float -> Company -> Company
increase k = everywhere (mkT (incS k))

-- "interesting" code for increase
incS :: Float -> Salary -> Salary
incS k (S s) = S (s * (1+k))

how come increase function compiles without binding anything for the first Company mentioned in its type signature.

Is it something like assigning to a partial function? Why is it done like that?

+3  A: 

Yes, it's the same concept as partial application. The line is a shorter (but arguably less clear) equivalent of

increase k c = everywhere (mkT (incS k)) c

As everywhere takes two parameters but is only given one, the type of everywhere (mkT (incS k)) is Company -> Company. Because this is exactly what increase k returns for each Float k, the resulting type of increase is Float -> Company -> Company.

OndraSej
It might be less clear at first, but it is one of the fundamental properties of curried functional programs and considered good practice by every experienced functional programmer.
Martijn