Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "François Bobot" <bobot@lri.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Generic printer patch
Date: Thu, 08 Dec 2011 08:28:04 +0100	[thread overview]
Message-ID: <4EE06704.5090107@lri.fr> (raw)
In-Reply-To: <4EE02213.70200@gmail.com>

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

  reply	other threads:[~2011-12-08  7:28 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
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 [this message]
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=4EE06704.5090107@lri.fr \
    --to=bobot@lri.fr \
    --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