[Haskell-cafe] Problem with percentage function?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Apr 20 22:00:10 UTC 2014


On Sun, Apr 20, 2014 at 09:50:43PM +0000, Chapman, Anthony Sergio wrote:
> Now it seems a bit peculiar to me that in your functions, you didn't
> define the input ie toPerc = printf "%.2f" .  (*100) instead of toPerc
> number = printf "%.2f" . (*100)

This expression uses the composition operator (.) rather than using function
application directly.  Note that for any functions 'f' and 'g', 'f . g' is
defined to be the function '\x -> f (g x)'.  Thus writing

    toPerc = printf "%.2f" . (*100)

just means

    toPerc = \x -> printf "%.2f" ((*100) x)

Desugaring the operator section gives

    toPerc = \x -> printf "%.2f" (x * 100)

and moving the lambda to become an argument of 'toPerc' gives

    toPerc x = printf "%.2f" (x * 100)

which is now in a form probably more familiar to you.

Tom


More information about the Haskell-Cafe mailing list