cdornan / fmt

New formatting library
BSD 3-Clause "New" or "Revised" License
56 stars 6 forks source link

Implement the Python formatting mini-language #20

Closed neongreen closed 3 years ago

neongreen commented 6 years ago

And when done, ping this guy: https://www.reddit.com/r/haskell/comments/72ubj8/naive_format_strings_using_template_haskell/dnowzd5/

His complaint is pretty valid:

Then, I want to format some floating point number rounded:

>>> value = 5.1234
>>> f"the value is {value:.2f}" 
'the value is 5.12'

I like this syntax because the formating part (i.e. .2f) is close to the one used by printf and a lot of unix tools I know and it does not clutter the readability of the string.

With fmt:

> putStrLn $ "the value is " +| fixedF 2 value
the value is 5.12

I always forgot the trailing space after "is" and I had to look at the documentation to find fixedF, everytime.

neongreen commented 6 years ago

Also see: https://hackage.haskell.org/package/PyF

cdornan commented 3 years ago

I think fmt does what it does really well — best to leave Python formatting to packages dedicated to this.