Friday 29 April 2016

Haskell: Partial applications

By using partial application, we can pass less number of arguments to a function, that expecting more arguments.

Example
additon x y = (x+y)
add10ToMe = additon 10

add10ToMe is result of partially applying function addition. add10ToMe is completely a new function, that takes a number n as input and add 10 to it.

add10ToMe 123 returns 133

add10ToMe 25 returns 35.
*Main> let addition x y = (x+y)
*Main> let add50ToMe = addition 50
*Main> let add10ToMe = addition 10
*Main> 
*Main> add10ToMe 123
133
*Main> add10ToMe 25
35
*Main> 
*Main> add50ToMe 23
73
*Main> add50ToMe 345
395


Previous                                                 Next                                                 Home

No comments:

Post a Comment