I always just use (++) or (<>) together with show:
> name = "Eric"
> age = 74
> "Hello, " <> name <> ". You are " <> show age <> "."
"Hello, Eric. You are 74."
Or maybe using concat or mconcat:
> name = "Eric"
> age = 74
> mconcat ["Hello, ", name, ". You are ", show age, "."]
"Hello, Eric. You are 74."
I don’t see the need for any other formatting functions. Formatting functions might be slightly less verbose, but those need things like implicit type conversion and variadic functions which are just not worth the benefit in my opinion.
The function format in that package is a variadic function. that does implicit type conversion. That is exactly what I find ugly. I think it is good that it is type-safe, but I still don’t like that it is variadic. And it is more verbose that the other printf-like functions which means that there is even less advantage over the solution that I use.
@carlosdagos In our projects, we’re using neat-interpolation where package when we need to format a lot of text. See example in summoner for the real-life use case. neat-interpolation automatically removes common indentation, so it’s quite lovely.
There is a blog post and a discussion on /r/haskell regarding string-interpolate package. Though it allows embedding calls to Haskell functions inside strings, this feature has its price. And the cost hear is a dependency on heavy haskell-src-exts library which is officially not maintained anymore. I’m trying to optimise dependencies of my Haskell libraries and if I don’t need to format a lot, using just ++ and <> is good enough actually! And neat-interpolation is a relatively small library for this purpose.
@jaror Not sure that YAML library with pretty-printing can support our style of formatting. As an author of the TOML configuration and parsing library, I understand how difficult it is to implement the library that supports various types of formatting users may want. Generating text is okay in our case: it doesn’t change often, it’s used only for couple files, so no need to bring another library.
At some point in the past, I was thinking about taking another route and implementing small interpolation DSL library. Because neat-interpolation sometimes had undesirable behaviour.