A few weeks ago I released pretty-simple-18.104.22.168.
I haven't done a release announcement in a while, so I wanted to list some of the new features that have been implemented in the last few releases. This post gives a short introduction to
pretty-simple, explains the new features, and lists some outstanding issues I'd like help with.
Introduction to pretty-simple
pretty-simple gives you an easy way to pretty-print any Haskell data type, as long as it has a
Show instance. You are not required to make your data type an instance of a custom typeclass, or even have the
Show instance produce valid Haskell.
Let's look at an example. Imagine you have the following datatypes:
You then create some values using these datatypes like the following:
If you run this in GHCi and
print bar, you get something like the following:
This is hard to read.
pretty-simple makes this easier to read:
Over the last few releases,
pretty-simple has gotten some interesting new features:
Debug.Pretty.Simplehas been added. It exports functions similar to
Debug.Trace. These functions can be used the same way you would use functions like
traceShowM, but the output is pretty-printed. If you have a large data structure you would like to print when doing printf-style debugging, I suggest taking a look at
A CLI program called
pretty-simplehas been added. This is a very simple CLI application that pretty-prints anything on stdin. This is useful if you accidentally
pPrint. Just copy and paste the output to the stdin of the CLI app.
The pretty-printing functions provided by
pretty-simplenow handle infinite data structures. You can attempt to pretty-print structures like infinite lists.
Pretty-printing functions like
pPrintnow detect whether they are printing to a TTY device (like a terminal), or just a plain file. By default, when printing to a plain file, coloring is disabled. Alternative functions like
pPrintForceColorhave been added with the previous behavior of always printing in color.
Check out the CHANGELOG.md to learn more.
Many people contributed to the above features and other bug fixes. Big thanks to:
And everyone else who reported issues!
Future Work (and Call to Action!)
There are a couple outstanding issues that would make
pretty-simple significantly better if solved. I'd appreciate help on any of these!
Highlight numbers in green.
Currently Haskell strings are highlighted in blue, but numbers aren't highlighted. It would be much easier to see numbers if they were highlighted.
This would require small changes to both the input parser and the output printer.
Gracefully handle non-balanced parentheses.
pretty-simplehas a bug where it ignores everything after a closing non-balanced parenthesis. It would be great to fix this.
This would require small changes to the input parser.
Create a live, interactive web-view of
This would be a website where new users could play around with
Please feel free to send a PR with something above either fully implemented, or partially implemented if you get stuck! If you're a beginning Haskeller, I will try to help out with any small problems, coding conventions, etc!
pretty-simple makes it easy to pretty-print complicated data structures. If you've ever found the normal