Printing a parseable representation

I am trying to find a generic way to print a parseable representation of generic objects. By parseable, I mean an string that can be pasted into the Julia REPL and parsed to equal the original value. My main use for this is debugging long running complex computations of there is a problem, so I don’t care if the result is kilobytes or more, it ends up in a logfile. It should preserve bit-by-bit accuracy for floats, but that should be possible. (There is always JLD2, but it is a bit of overkill for simpler cases and does not work well in logfiles).

I found that there is no generic API to do this (see discussion, discussion). Eg 3-argument show with MIME"text/plain" should be “human readable”, and 2-argument show “should be parseable Julia code when possible”, so it is not guaranteed.

Also, I want the method to error if parseable representation is not possible. The idea is that it is better to test this early, before running costly computations, instead of finding that it is not possible.

First, does this need a new generic function (in package)? I think yes, currently no API in Base is designed for this.

Second, what would be the best approach so that it requires very little (if any) modification of existing code? I think that defining the methods for primitive types in Base (numbers, arrays, etc) and then relying on ConstructionBase.jl for struct would make sense.

Third: namespaces. I think it would make sense to qualify all types (except those exported from Base) with a package name, with the implicit rule that if you see a package name, it should at least be imported.

If I missed an existing package to do this, please let me know, otherwise your opinions and suggestions would be appreciated. I am currently planning to write a package doing this if necessary.