Friday 29 April 2016

Haskell: Point-free style

Point-free style programming is a programming paradigm in functional programming, in which a function definition does not include information regarding its arguments, function is defined through function composition.

square x = x*x
add10Tox x = 10 +x

process = square.add10Tox

process function is defined in point-free style (don’t include any arguments). By using point-free style, we can develop program in compact and cleaner way.


process 10 = square.add10Tox 10 = square(add10Tox 10) = square (10 + 10) = square (20) = 400
*Main> let square x = x*x
*Main> let add10Tox x = 10 +x
*Main> 
*Main> let process = square.add10Tox
*Main> 
*Main> process 10
400
*Main> process 20
900



Previous                                                 Next                                                 Home

No comments:

Post a Comment