Le 07/12/2011 16:28, Jérémie Dimino a écrit :
Hi,
I have made a patch for ocaml 3.12.1 which allow to have a generic
printing function. The patch is available here:
[...]
Of course it is limited to what the compiler knows, for example the
following function will always returns "[<poly>;<poly>]":
let f x = show [x; x]
But i think it is already very useful for debugging.
Great job in so few time. That's right that can be an awesome feature. I
haven't tested it yet. I just read the diff. But I have some questions :
1) If I understand well the "%show" command is expanded into the ocaml
code (lambda-code) which can print the type. So, for instance, in the
case of a list, your code generates a recursive function "aux" and it
applies this new "aux" function to the argument of "%show". Do you plan
to add in the module List a function :
val string_of_list : ('a -> string) -> 'a list -> string
and to generate only the call to this function instead of generating the
"aux" function every time? Or do you do it purposely?
2) Could you imagine to generalize it to Format.formatter or to
out_channel (without creating a string and concatenating)? Romain Bardou
add in the mantis tracker (I can't give you the bugtracking number since
mantis "is currently offline for maintenance") a feature wish for a new
conversion specification that can print anything. Do you think you can
fulfill is dream?
3) Is it impossible to reuse/merge with the code of the top level that
print ocaml values?
Thank you for providing this code. Funny the way you find the user
defined function. Be careful to not implement type classes in Ocaml ;)
--
François Bobot
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs