From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pB7HYxC9009929 for ; Wed, 7 Dec 2011 18:34:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmoFAOGi307VuiYS/2dsb2JhbABDhDZQoxmCNYEFgXIBAQQBDBcEUgULCQIaAiYCAiwrBogaAqU1kVUUgSCIaoEWBKcP X-IronPort-AV: E=Sophos;i="4.71,315,1320620400"; d="scan'208";a="134401491" Received: from solaria.dimino.org ([213.186.38.18]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Dec 2011 18:34:54 +0100 Received: from arrakis (localhost.localdomain [127.0.0.1]) by solaria.dimino.org (Postfix) with ESMTP id 8563580088; Wed, 7 Dec 2011 18:34:53 +0100 (CET) Received: by arrakis (Postfix, from userid 1000) id 1BA2F11F2D4; Wed, 7 Dec 2011 18:34:52 +0100 (CET) Message-ID: <1323279292.32238.48.camel@arrakis> From: =?ISO-8859-1?Q?J=E9r=E9mie?= Dimino To: =?ISO-8859-1?Q?Fran=E7ois?= Bobot Cc: caml-list@inria.fr Date: Wed, 07 Dec 2011 18:34:52 +0100 In-Reply-To: <4EDF9AAE.5050604@crans.org> References: <1323271707.32238.17.camel@arrakis> <4EDF9AAE.5050604@crans.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.0.3-3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id pB7HYxC9009929 Subject: Re: [Caml-list] Generic printer patch Le mercredi 07 décembre 2011 à 17:56 +0100, François Bobot a écrit : > 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? It is not in the lambda-code: i get the typed tree, generate for every occurrence of %show a parsetree using types and type this parsetree. The result is inserted in place of %show. For the rest, yes, it is how it works. Of course it is better if the printer is defined once and for all in its module. I did not modify the standard library because i did not wanted to rebuild all my libraries. > 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? For using formatter, yes, we can do that. This patch is more a proof of concept. If we want to really use it we can do something more generic than just generating printers. For example we could generate type representation values from which we would generate printers, marshallers, ... For the new conversion specification i don't think it is possible with the way the stdlib implements printf. The best you can do is something like: printf "%a" show value However it is possible with batteries' formatted printing (Print.printf p"%s" ...). > 3) Is it impossible to reuse/merge with the code of the top level that > print ocaml values? No, the toplevel use outcome trees (defined in Outcometree). > Thank you for providing this code. Funny the way you find the user > defined function. Be careful to not implement type classes in Ocaml ;) :-) -- Jérémie