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 pB85KDpj005217 for ; Thu, 8 Dec 2011 06:20:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkkBALBI4E5CbwQakGdsb2JhbABDhDZQpVMiAQEBAQkJDQcUBCGBcgEBBQwXBAsBDTgCDwkCGAICBRYLAgIJAwIBAgFFEwgBAQWIBqQ+aZElB4E0hmiCAoEWiDKSB4x6 X-IronPort-AV: E=Sophos;i="4.71,318,1320620400"; d="scan'208";a="122519984" Received: from out2.smtp.messagingengine.com ([66.111.4.26]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 08 Dec 2011 06:20:07 +0100 Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 42CF52146B for ; Thu, 8 Dec 2011 00:20:06 -0500 (EST) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 08 Dec 2011 00:20:06 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=BFaNMTYGNYXDXfhatVsptU 6Fqro=; b=LXxq4rO4TpDH50bdLYVPG9lpuYdo9/9yHo14Cnjj+TIAr7rG9xGQvp j3tb7ScBKvlYtMalRUP7mr+FMbuhi4+EmC4ZWP9Aw2eSBd6ni8teR2wrMgZXD0QT qADKJactBluP1qIwmZZAgOE19Vt3+r/3QlMxVrjiqtJThhu9f4KFY= X-Sasl-enc: 5F+MOUo77ZGErfEC8//Cpxc2zS8PSIW6ux2+9xY0KuNG 1323321605 Received: from [192.168.2.3] (c-98-248-39-171.hsd1.ca.comcast.net [98.248.39.171]) by mail.messagingengine.com (Postfix) with ESMTPSA id C263B482595 for ; Thu, 8 Dec 2011 00:20:05 -0500 (EST) Message-ID: <4EE04A80.6090409@ens-lyon.org> Date: Wed, 07 Dec 2011 21:26:24 -0800 From: Martin Jambon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20101023 Lightning/1.0b3pre Thunderbird/3.1.3 MIME-Version: 1.0 To: caml-list@inria.fr References: <1323271707.32238.17.camel@arrakis> In-Reply-To: <1323271707.32238.17.camel@arrakis> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Generic printer patch Thanks Jérémie for doing this, it's a very useful feature. I would like to fetch the git repository but it won't let me: $ git clone 'http://www.dimino.org/git/ocaml-3.12.1-print.git' Cloning into ocaml-3.12.1-print... fatal: http://www.dimino.org/git/ocaml-3.12.1-print.git/info/refs not found: did you run git update-server-info on the server? Martin On 12/07/2011 07:28 AM, Jérémie Dimino 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 "[; ]": > > 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, >