[Haskell-cafe] Best way to format a number

2007-11-20 Thread Maurí­cio

Hi,

I would like to get a string for a number
using always 2 digits (i.e., 75 would be
75, 3 would became 03). What is the
best way to do that? I tried

printf %02d\n 3

which gives me the correct string, but
ghci always ends that call with a

*** Exception: Prelude.undefined

message. What else should I try? Can
Text.PrettyPrint do that?

Thanks,
Maurício

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Best way to format a number

2007-11-20 Thread Don Stewart
briqueabraque:
 Hi,
 
 I would like to get a string for a number
 using always 2 digits (i.e., 75 would be
 75, 3 would became 03). What is the
 best way to do that? I tried
 
 printf %02d\n 3
 
 which gives me the correct string, but
 ghci always ends that call with a
 
 *** Exception: Prelude.undefined
 
 message. What else should I try? Can
 Text.PrettyPrint do that?
 

It's to do with ghci's defaulting. This is fixed in ghc 6.8:

Prelude Text.Printf printf %02d\n 3
03

You can work around it for now with:

Prelude Text.Printf printf %02d\n 3  return ()  
03

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Best way to format a number

2007-11-20 Thread Shachaf Ben-Kiki
On Nov 20, 2007 7:07 PM, Don Stewart [EMAIL PROTECTED] wrote:
 You can work around it for now with:

 Prelude Text.Printf printf %02d\n 3  return ()
 03

It may be simpler to specify the type explicitly:

Prelude Text.Printf printf %02d\n 3 :: IO ()
03

Shachaf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe