Le jeudi 08 décembre 2011 à 22:39 +0100, Gabriel Scherer a écrit : > Of course, the "right" way to print/marshal data without changing the > language is to build a printer for your type from printer combinators. > Such combinators are available for example: > - in Jane Street Core library ( a Sexpable interface in each datatype module ) > - in Xavier Clerc's Kaputt testing framework : > http://kaputt.x9c.fr/distrib/api/Utils.html > > You can also use metaprogramming (.. camlp4) to generate printer > functions from datatypes description automatically, using such > combinators. See: > - Markus Mottl's 'type-conv': http://hg.ocaml.info/release/type-conv > - Jeremy Yallop's 'deriving': http://code.google.com/p/deriving/
These solutions would be usable only if everybody were using it. Right now almost nobody use them, and so if you want to print types coming from external library you still have to write the printer yourself. > Of course, printing values magically is still easier: you don't have > to build the printer yourself, passing subtype printers when > necessary, etc. I think Std.dump is reasonable for quick hacks or > debugging usage. If think my hack is reasonable too, you just have to replace ocamlc and ocamlopt (if you already use ocaml 3.12.1) by the new compilers and it will work. Of course don't use it in production code ;-) Cheers, -- Jérémie -- 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
