haskell - Formatting a list of doubles into a string -
i trying format list of doubles string. turn list such as:
[0.38, 0.94]
into like:
"astring 0.380 0.940"
i have tried:
"astring" ++ map (printf "%7.3f") [0.38, 0.94]
and feedback:
<interactive>:80:19: no instance (printftype char) arising use of `printf' possible fix: add instance declaration (printftype char) in first argument of `map', namely `(printf "%7.3f")' in second argument of `(++)', namely `map (printf "%7.3f") [0.38, 0.94]' in expression: "astring" ++ map (printf "%7.3f") [0.38, 0.94]
i've not been able fix this. have unable compose signature works.
thank you
the problem map (printf "%7.3f") [0.38, 0.94]
of type [string]
, not string
. use concatmap
:
prelude text.printf> "astring" ++ concatmap (printf "%7.3f") [0.38, 0.94] "astring 0.380 0.940"
Comments
Post a Comment