[Haskell-cafe] Problem with percentage function?

Ben midfield at gmail.com
Mon Apr 21 00:53:34 UTC 2014


since this seems to come up with some regularity, i'm curious, does the haskell standard or ghc implement

Florian Loitsch, "Printing Floating-Point Numbers Quickly and Accurately with Integers"

for floating types?  it seems like that would go a long way towards preventing this kind of confusion.  i seem to recall brian o'sullivan using this algorithm for aeson or something.

b

On Apr 20, 2014, at 3:00 PM, Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:

> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4885 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140420/97e2f882/attachment.bin>


More information about the Haskell-Cafe mailing list