tags:

views:

85

answers:

2

with this code

digs 0 = []

digs x = x `mod` 1000 : digs (x `div` 1000)

for example: 24889375
we take the result [375,889,24]

how can i make this one ["375","889","024"]

+3  A: 
Prelude> import Text.Printf
Prelude Text.Printf> map (printf "%03d" :: Int -> String) [375,889,24]
["375","889","024"]
KennyTM
how can I put this together with the code up there
marco
@ifan: `map (printf "%03d" :: Int -> String) (digs 24889375)`.
KennyTM
thank you a lot...
marco
Any particular reason to use printf instead of show?
svenningsson
@sven: `show 24 == "24"`, not `"024"`.
KennyTM
Ah, right. Totally missed that one.
svenningsson
+1  A: 

The most idiomatic way to do this is to use the functions map and show.

Prelude> map show [375,889,24]
["375","889","024"]

show can be used to convert most values to a string. map applies that function to every element of a list map.

svenningsson
that supplies ["375","889","24"] except 0
marco
OK then: `map (tail . show . (+ 1000)) [375, 889, 24]`
Yitz