caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] install_printer
@ 2002-01-25  3:56 Ian Zimmerman
  2002-01-25  5:58 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Zimmerman @ 2002-01-25  3:56 UTC (permalink / raw)
  To: OCAML


Hi, I can hook into the toplevel loop to modify printing of simple
types like int with #install_printer, but what about polymorphic
types?  Say I want the toplevel to do this:

# [1; 2] ;;
- : int list = List (1, 2)

so I started to write my printer function:

let list_printer ppf l =
  pp_open_box ppf 6;	(* if break needed, indent to the paren *)
  pp_print_string ppf "List (";
  
  (* now what??? *)
  
Basically, I am looking for a hook into the toploop that I can _call_
(not modify) to make it print a value (of any type) according to its
current printers.  Is that possible?

-- 
Ian Zimmerman, Oakland, California, U.S.A.
GPG: 433BA087  9C0F 194F 203A 63F7 B1B8  6E5A 8CA3 27DB 433B A087
In his own soul a man bears the source
from which he draws all his sorrows and his joys.
Sophocles.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] install_printer
  2002-01-25  3:56 [Caml-list] install_printer Ian Zimmerman
@ 2002-01-25  5:58 ` Daniel de Rauglaudre
  2002-01-25  6:34   ` Ian Zimmerman
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel de Rauglaudre @ 2002-01-25  5:58 UTC (permalink / raw)
  To: OCAML

Hi,

On Thu, Jan 24, 2002 at 07:56:58PM -0800, Ian Zimmerman wrote:

> Hi, I can hook into the toplevel loop to modify printing of simple
> types like int with #install_printer, but what about polymorphic
> types?

For a general printing of all values of all types, use the hook
Toploop.print_out_value. You can change it to point to your function.

This function must take a value of type Outcometree.out_value and
print it. The module Outcometree is in the installed OCaml library
directory.

The default value of !Toploop.print_out_value is the function "print_outval"
located in the OCaml sources file toplevel/genprintval.ml. You can make your
own version by copying this function and adapt it for your own usage.

Another example is the "revised syntax" of Camlp4 in the OCaml
sources, file "camlp4/top/rprint.ml". (use "camlp4r pr_o.cmo
camlp4/top/rprint.ml" to see this file in normal syntax, if you
prefer).

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] install_printer
  2002-01-25  5:58 ` Daniel de Rauglaudre
@ 2002-01-25  6:34   ` Ian Zimmerman
  2002-01-25  9:53     ` Daniel de Rauglaudre
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Zimmerman @ 2002-01-25  6:34 UTC (permalink / raw)
  To: OCAML


itz> Hi, I can hook into the toplevel loop to modify printing of simple
itz> types like int with #install_printer, but what about polymorphic
itz> types?

Daniel> For a general printing of all values of all types, use the hook
Daniel> Toploop.print_out_value. You can change it to point to your function.

Daniel> This function must take a value of type Outcometree.out_value and
Daniel> print it. The module Outcometree is in the installed OCaml library
Daniel> directory.

Daniel> The default value of !Toploop.print_out_value is the function "print_outval"
Daniel> located in the OCaml sources file toplevel/genprintval.ml. You can make your
Daniel> own version by copying this function and adapt it for your own usage.

Daniel> Another example is the "revised syntax" of Camlp4 in the OCaml
Daniel> sources, file "camlp4/top/rprint.ml". (use "camlp4r pr_o.cmo
Daniel> camlp4/top/rprint.ml" to see this file in normal syntax, if you
Daniel> prefer).

Thanks.  I take it that your answer is 3.04 specific; actually I am
working with 3.02.  I will just wait with this functionality until I
upgrade. 

Pretty amazing that it _is_ now possible, really. :-)  Maybe because
you needed something like it for p4?

-- 
Ian Zimmerman, Oakland, California, U.S.A.
GPG: 433BA087  9C0F 194F 203A 63F7 B1B8  6E5A 8CA3 27DB 433B A087
In his own soul a man bears the source
from which he draws all his sorrows and his joys.
Sophocles.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] install_printer
  2002-01-25  6:34   ` Ian Zimmerman
@ 2002-01-25  9:53     ` Daniel de Rauglaudre
  2002-01-28 12:31       ` M E Leypold @ labnet
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel de Rauglaudre @ 2002-01-25  9:53 UTC (permalink / raw)
  To: OCAML

Hi,

On Thu, Jan 24, 2002 at 10:34:53PM -0800, Ian Zimmerman wrote:

> Thanks.  I take it that your answer is 3.04 specific

Right.

> Pretty amazing that it _is_ now possible, really. :-)  Maybe because
> you needed something like it for p4?

Right, also. One user of my "revised syntax" complained that his
output was in the "old" syntax.

You can also customize the printed types, the printed signature items
and the result of a toplevel phrase. Jean-Marc Eber wrote a version
to print the output values in XML format. What is missing now is to
be able to use that in the compilers ocamlc and ocamlopt, to customize
the output of the types in the error messages and of the -i option.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] install_printer
  2002-01-25  9:53     ` Daniel de Rauglaudre
@ 2002-01-28 12:31       ` M E Leypold @ labnet
  0 siblings, 0 replies; 5+ messages in thread
From: M E Leypold @ labnet @ 2002-01-28 12:31 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: OCAML

Daniel de Rauglaudre writes:
 > Hi,
 > 
 > On Thu, Jan 24, 2002 at 10:34:53PM -0800, Ian Zimmerman wrote:
 > 
 > > Thanks.  I take it that your answer is 3.04 specific
 > 
 > Right.
 > 
 > > Pretty amazing that it _is_ now possible, really. :-)  Maybe because
 > > you needed something like it for p4?
 > 
 > Right, also. One user of my "revised syntax" complained that his
 > output was in the "old" syntax.
 > 
 > You can also customize the printed types, the printed signature items
 > and the result of a toplevel phrase. Jean-Marc Eber wrote a version
 > to print the output values in XML format. What is missing now is to
 > be able to use that in the compilers ocamlc and ocamlopt, to customize
 > the output of the types in the error messages and of the -i option.


I'd like you to know that I really appreciate that. I've long hold the
opinion that a proper data type must come with a printer and a parser
(the least thing you can say here is, that it simplifies debugging a
lot), and this is a real incentive to upgrade to 3.04.

Thanks again :-) -- Markus

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-01-28 12:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-25  3:56 [Caml-list] install_printer Ian Zimmerman
2002-01-25  5:58 ` Daniel de Rauglaudre
2002-01-25  6:34   ` Ian Zimmerman
2002-01-25  9:53     ` Daniel de Rauglaudre
2002-01-28 12:31       ` M E Leypold @ labnet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).