From: Alex Rubinsteyn <alex.rubinsteyn@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Generic printer patch
Date: Wed, 7 Dec 2011 11:46:09 -0500 [thread overview]
Message-ID: <CAMB58pGmj6K6U1S79-WEx+k1g=Y+d6=Y4HM9nMxEixUFPkN22w@mail.gmail.com> (raw)
In-Reply-To: <1323271707.32238.17.camel@arrakis>
[-- Attachment #1: Type: text/plain, Size: 1632 bytes --]
Cool! Thanks for writing this. Can you explain how defining a custom
printer works? The new language features still bewilder me.
On Dec 7, 2011 10:29 AM, "Jérémie Dimino" <jeremie@dimino.org> wrote:
> Hi,
>
> I have made a patch for ocaml 3.12.1 which allow to have a generic
> printing function. The patch is available here:
>
> http://www.dimino.org/ocaml-3.12.1-generic-print.patch
>
> Here is how to use it:
>
> external show : 'a -> string = "%show"
>
> let () = print_endline (show ([1; 2; 3], Some "foo"))
>
> this will print:
>
> ([1; 2; 3], Some "foo")
>
> It is also possible to define custom printers, for example:
>
> module StringMap : sig
> include Map.S with type key = string
> val string_of_t : ('a -> string) -> 'a t -> string
> end = struct
> include Map.Make(String)
> let string_of_t (type a) string_of_a (m : a t) =
> show (bindings m)
> end
>
> let () = print_endline (show (StringMap.singleton "x" 1))
>
> will print:
>
> [("x", 1)]
>
> 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.
>
> The git repo is here:
>
> http://www.dimino.org/gitweb/?p=ocaml-3.12.1-print.git;a=summary
>
> 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
>
>
[-- Attachment #2: Type: text/html, Size: 2512 bytes --]
next prev parent reply other threads:[~2011-12-07 16:46 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 [this message]
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
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='CAMB58pGmj6K6U1S79-WEx+k1g=Y+d6=Y4HM9nMxEixUFPkN22w@mail.gmail.com' \
--to=alex.rubinsteyn@gmail.com \
--cc=caml-list@inria.fr \
/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