Is there a way to make ghci use a custom pretty-printing function instead of show for certain types? A more general question: what are the general guidelines to make a library as usable as possible in interactive mode? Thanks.
You can specify a custom pretty-printing function using the --interactive-print flag and naming any function in scope with the type C a => a -> IO () for any constraint C. (See Section 2.4.9 of the docs for details.)
ghci --interactive-print=MyModule.prettyPrint
This means you can specify your own function from your own typeclass. There's no way to do this just for a specific type, but your custom class can always include a fallback instance like
instance Show a => PrettyPrint a where prettyPrint = show
This will require at least OverlappingInstances to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With