From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr 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 pB87SAbh009070 for ; Thu, 8 Dec 2011 08:28:10 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcDAMRl4E6K54gDgWdsb2JhbABDhDZQpVIiAQEWJiWBcgEBBQwXBAsBBUARCQIaAgUWCwICCQMCAQIBRRMIAheHdKUjkTGBNIZoggKBFgSaNYxa X-IronPort-AV: E=Sophos;i="4.71,318,1320620400"; d="scan'208";a="122530610" Received: from rouge.crans.org ([138.231.136.3]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 08 Dec 2011 08:28:05 +0100 Received: from localhost (localhost.crans.org [127.0.0.1]) by rouge.crans.org (Postfix) with ESMTP id C648685CE for ; Thu, 8 Dec 2011 08:28:04 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at crans.org Received: from rouge.crans.org ([10.231.136.3]) by localhost (rouge.crans.org [10.231.136.3]) (amavisd-new, port 10024) with LMTP id P04lNA3SJKH0 for ; Thu, 8 Dec 2011 08:28:04 +0100 (CET) Received: from [129.175.29.25] (lri29-25.lri.fr [129.175.29.25]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTPSA id AAE6185CA for ; Thu, 8 Dec 2011 08:28:04 +0100 (CET) Message-ID: <4EE06704.5090107@lri.fr> Date: Thu, 08 Dec 2011 08:28:04 +0100 From: =?UTF-8?B?RnJhbsOnb2lzIEJvYm90?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111114 Icedove/3.1.16 MIME-Version: 1.0 To: caml-list@inria.fr References: <1323271707.32238.17.camel@arrakis> <4EE02213.70200@gmail.com> In-Reply-To: <4EE02213.70200@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Validation-by: bobot@lri.fr Subject: Re: [Caml-list] Generic printer patch Le 08/12/2011 03:33, Edgar Friendly a écrit : > I'm interested in having compile-time reflection like this, but maybe > with a bit more generality. Maybe an identifier can be built out of the > type in a generic way... > > external show : 'a -> string = "%type_to_string" > external print : out_channel -> 'a -> unit > external cmp : 'a -> 'a -> int = "%type_compare" When does this function return something different than 0? Jérémie Dimino a écrit : > 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, ... I'm not sure that we can use a function like : external type_expr : 'a -> 'a type_expr (with GADT) (or just external type_expr : 'a -> type_expr) in order to write a generic printer, since during the definition the value is polymorphic. We only know the type at the call site. Of course the user can call the function himself : val gen_to_string : 'a type_expr -> 'a -> string let v = ... in (** debug *) print_string (gen_to_string (type_expr v) v) Perhaps we can ask that the first argument is implicitly given by the OCaml compiler (extending the "type a" notation) : let gen_to_string type (a:repr) (x:a) = ... (repr : a type_expr) ... .... let v = ... in (** debug *) print_string (gen_to_string v) In fact the LexiFi extension to OCaml called implicit argument, can do something similar : http://www.lexifi.com/blog/implicit-values (You can look for "Combined with GADTs, one could do something like (not tested!):") But with all these solutions we will never be able to write a generic printer which can print values that come from a dynamic plugin (um.. wait and with first order modules?...) -- François Bobot