One of my colleagues just dumbfounded me with this question: why do we have to code pretty-printers for our types (either manually or via ppx_deriving) whereas the OCaml toplevel can print them all by itself?

Off the top of my head:
- The types may be abstract/opaque, so we may not want to expose the implementation when printing.
- And the implementation may be complicated so we should better specify what is the most important.

Otherwise it wouldn't be really pretty…

@amiloradovsky But having an optional deriver such as Haskell's `deriving Show` would be nice and wouldn't cause the problems you mention.

It may be possible to implement the derivation as a functor, without type-classes, but apparently few people care.

@otini (I read this thread to fast, sorry: you already mentioned it above.)

@otini the toplevel has access to the typing environment and the type of expressions that are handled. Those get erased at compile time.

I guess this is not a definitive answer, and the compiler could integrate some sort of deriving show.

@khady @Armael Yes, true, abstract types would probably make things very difficult in the absence of ad hoc polymorphism.

Sign in to participate in the conversation
Functional Café is an instance for people interested in functional programming and languages.