From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pB7FSV7B001176 for ; Wed, 7 Dec 2011 16:28:31 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvkGAPWE307VuiYS/2dsb2JhbABDhDZQpU1+B4IFFwRrHAImAi4xHIgABpZxjgKRUxSBIIhqgRYEpw8 X-IronPort-AV: E=Sophos;i="4.71,314,1320620400"; d="scan'208";a="122433307" Received: from solaria.dimino.org ([213.186.38.18]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 07 Dec 2011 16:28:28 +0100 Received: from arrakis (localhost.localdomain [127.0.0.1]) by solaria.dimino.org (Postfix) with ESMTP id DBDB180088 for ; Wed, 7 Dec 2011 16:28:27 +0100 (CET) Received: by arrakis (Postfix, from userid 1000) id 55B2811F2D4; Wed, 7 Dec 2011 16:28:27 +0100 (CET) Message-ID: <1323271707.32238.17.camel@arrakis> From: =?ISO-8859-1?Q?J=E9r=E9mie?= Dimino To: "caml-list@inria.fr" Date: Wed, 07 Dec 2011 16:28:27 +0100 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 pB7FSV7B001176 Subject: [Caml-list] Generic printer patch 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 "[; ]": 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