Reputation: 4127
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?
Upvotes: 3
Views: 180
Reputation: 692
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
.
Upvotes: 3