-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Lowering" types before rendering via writemime #9633
Comments
I'm confused. If you have a type T, you only implement one |
Sure, I'm not saying otherwise. But different displays support different mime outputs in general, so if you want to support a range of displays you will have to implement a range of (If it's more precise, replace "displays" with "output formats". The point stands) |
It would actually be sufficient to be able to overload writemime(io::IO, m, f::Foo) = writemime(io, m, Table(...)) which has the advantage that it doesn't introduce a new function. However, it's ambiguous with any fallback methods. Not sure if there's a good way around that. |
Now I think about it, the Another way to go might be to have a separate |
The current
writemime
method of rendering types for display forces one to write a method for each mime typeM
, for each displayable typeT
– which is a lot of definitions if you want to support a wide range of displays.To me this is a red flag for lack of abstraction; a table is a table is a table regardless of whether it's rendered in HTML, the terminal, as an image, whatever, so you shouldn't have to write table-lowering code
T×M
times. Instead I want to be able to write:The
Header
andTable
types would provide thewritemime
methods for you, so that the one definition gets you display on every device.Equally, you could (for example) take advantage of a library like Markdown.jl for rich formatting:
which would tell Julia to print the type
DataFrame
as "DataFrames.DataFrame" where possible (e.g. terminal, IJulia) and fall back on plain text everywhere else (assuming I didn't just make up theparent
function). This is very similar to what I'm doing already in Juno, and it works nicely.I'm not certain how best to implement this yet. My rough idea is to have a
writemime
fallback that looks like:where
applylower
applies thelower
function untilx
stops changing. If there's nolower
method forx
, you get a method error, since there's no other way to display it.This complicates things slightly for fallback methods (e.g. all types can write to text/plain by default) which override this method, since they'll have to call
applylower
explicitly. Since there aren't many of those, though, it's perhaps not a big problem.I suspect there might be a more elegant design to be had here, so I'm open to suggestions.
The text was updated successfully, but these errors were encountered: