Skip to content
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

Printf format: %v or %V to print any value #4956

Closed
vicuna opened this issue Jan 7, 2010 · 1 comment
Closed

Printf format: %v or %V to print any value #4956

vicuna opened this issue Jan 7, 2010 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jan 7, 2010

Original bug ID: 4956
Reporter: Bardou
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-12-07T16:04:48Z)
Resolution: suspended
Priority: normal
Severity: feature
Version: 3.11.1
Category: standard library
Monitored by: mww mehdi @ygrek @glondu @Chris00 @mjambon

Bug description

The idea is to be able to write :

Printf.printf
"Hello %v, %v and %v are OCaml values"
"user name"
1
[ true; false ];

Which would print something like :

Hello "user name", 1 and [ true; false ] are OCaml values

Additional information

This would be very useful especially when debugging.

The toplevel already contains a mechanism to print any type, except functions and abstract values. The same printing conventions could be used. In particular : functions could be printed as , abstract values as .

A mechanism should be added to the typing of formats so that %v (or %V) accepts any value type. Then, code generation could use the type information to produce the correct printer.

This correct printer cannot be produced for polymorphic values, but they could be printed as .

Maybe %V is better than %v, as the convention seems to be that uppercase letter use OCaml conventions.

@vicuna
Copy link
Author

vicuna commented Jan 12, 2010

Comment author: @pierreweis

This is a major feature wish that requires careful thinking and a lot of work!

Furthermore, we would not have a completely satisfactory solution in the end (due to this catch all case that tend to propagate, as far as you use polymorphic functions). The correct solution to get this feature in its full glory is a major modification of the type system along the lines of G'Caml.

In short, a natural feature wish in a strongly typed polymorphic language; we had it in mind for decades; unfortunately, we are not yet ready to offer it, even in the rather limited extent you proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants