Andreas Kalivas <[EMAIL PROTECTED]> wrote,

> Hello everybody,
> I have been learning haskell lately and I am trying to write a program that 
> at some point displays a float number to the screen.
> The function I used to accomplish this was show :
> 
> putStr (show myFloat)
> 
> The problem is that show was displaying the number in scientific format, 
> like 1.5e-2 while I wanted it to show like 0.015 and also control the 
> number of decimal points.
> After some search I found the function showGFloat but I can't use it the 
> way i used show because it returns (String -> String) and not String. I 
> can't seem to understand this ShowS type.
> Could someone please help me with this by giving an example of how to 
> display a float?

The String argument to functions of type ShowS is just a
string that will be put behind the string contained in
ShowS - ie, in your case behind the float rendering produced
by showGFloat.  In other words, just write 

  putStr (showGFloat myFloat "")

The reason for this "strange" type of the showXXX functions
is that it is much more efficient to extend a string in this
way on its right than using (++).

Manuel

Reply via email to