caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jérémie Dimino" <jeremie@dimino.org>
To: "François Bobot" <francois.bobot@crans.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Generic printer patch
Date: Wed, 07 Dec 2011 18:34:52 +0100	[thread overview]
Message-ID: <1323279292.32238.48.camel@arrakis> (raw)
In-Reply-To: <4EDF9AAE.5050604@crans.org>

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



  reply	other threads:[~2011-12-07 17:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07 15:28 Jérémie Dimino
2011-12-07 16:46 ` Alex Rubinsteyn
2011-12-07 17:10   ` Jérémie Dimino
2011-12-07 16:56 ` François Bobot
2011-12-07 17:34   ` Jérémie Dimino [this message]
2011-12-08 12:00     ` Romain Bardou
2011-12-08 14:21       ` Gerd Stolpmann
2011-12-08 18:20       ` Martin Jambon
2011-12-08 21:39         ` Gabriel Scherer
2011-12-09  7:22           ` Jérémie Dimino
2011-12-09  9:26             ` Gabriel Scherer
2011-12-09  7:15         ` Jérémie Dimino
2011-12-08  2:33 ` Edgar Friendly
2011-12-08  7:28   ` François Bobot
2011-12-08  9:00   ` Alain Frisch
2011-12-08  9:24     ` Gerd Stolpmann
2011-12-08 10:32       ` Alain Frisch
2011-12-08 10:41         ` Jonathan Protzenko
2011-12-08 12:00           ` Philippe Veber
2011-12-08  5:26 ` Martin Jambon
2011-12-08  6:52   ` Jérémie Dimino
2011-12-08  7:44     ` Martin Jambon
2011-12-08  9:37       ` Jérémie Dimino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323279292.32238.48.camel@arrakis \
    --to=jeremie@dimino.org \
    --cc=caml-list@inria.fr \
    --cc=francois.bobot@crans.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).