* [Caml-list] Custom prettyprinter for polymorphic datatype
@ 2001-03-22 21:02 John R Harrison
2001-03-27 8:44 ` Xavier Leroy
0 siblings, 1 reply; 6+ messages in thread
From: John R Harrison @ 2001-03-22 21:02 UTC (permalink / raw)
To: caml-list; +Cc: John Harrison
In CAML Light and OCaml, how do I install a custom printer for a
polymorphic datatype so that the subcomponents print in the usual way?
For example, suppose I decided to print lists with the elements
separated by "," instead of ";". (This is a bad idea of course, but
serves as a simple example.) Obviously I can write a recursive
function that passes over a list and does X at each element, but how
do I make X work on arbitrary types? Preferably as part of "X" the
custom printer would itself be called recursively if the elements
contain more lists.
If I could just get hold of a "standard printer" function
print_value : 'a->unit
then presumably I could use that. Is this possible? Or is there a
better way?
John.
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Custom prettyprinter for polymorphic datatype
2001-03-22 21:02 [Caml-list] Custom prettyprinter for polymorphic datatype John R Harrison
@ 2001-03-27 8:44 ` Xavier Leroy
2001-04-05 8:07 ` [Caml-list] Does ocamldebug work for the non-cygwin version of Ocaml 3.01 for Windows? Mattias Waldau
0 siblings, 1 reply; 6+ messages in thread
From: Xavier Leroy @ 2001-03-27 8:44 UTC (permalink / raw)
To: John R Harrison; +Cc: caml-list
> In CAML Light and OCaml, how do I install a custom printer for a
> polymorphic datatype so that the subcomponents print in the usual way?
> If I could just get hold of a "standard printer" function
> print_value : 'a->unit
> then presumably I could use that. Is this possible? Or is there a
> better way?
It is not currently possible. The system printer works by traversing
both the value to be printed and its type. In the toplevel loop, the
type is provided by the type-checker. But user-defined printers have
no convenient way to recover and manipulate this type information, so
they can't call back the system printer.
There is no really good solution to this problem. The workaround that
I use is to write custom printers for polymorphic datatypes that are
parameterized by printers for the type parameters, e.g.
print_list : ('a -> unit) -> 'a list -> unit
or
print_hashtable : ('a -> unit) -> ('b -> unit) ->
('a, 'b) Hashtbl.t -> unit
Then, I partially apply these printers to the (monomorphic) types of
interest and install the partial applications as custom printers:
let print_int_list = print_list Format.print_int;;
#install_printer print_int_list;;
let print_string_list = print_list Format.print_string;;
#install_printer print_string_list;;
Provided there are only a few list types you're interested in, this
can work. But I agree a more general solution would be nicer.
- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Does ocamldebug work for the non-cygwin version of Ocaml 3.01 for Windows?
@ 2001-04-06 21:28 Hao-yang Wang
2001-04-06 21:59 ` Jerome Vouillon
0 siblings, 1 reply; 6+ messages in thread
From: Hao-yang Wang @ 2001-04-06 21:28 UTC (permalink / raw)
Cc: caml-list
>No, ocamldebug doesn't work on the "pure Win32" port of OCaml, while
>it works (albeit a bit slowly) on the Cygwin port. And, yes, the Web
>site should explain better the differences between these two ports.
How difficult it would be to make ocamldebug work with the "pure Win32"
port, without backstep and time travel?
Thanks,
Hao-yang Wang
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Does ocamldebug work for the non-cygwin version of Ocaml 3.01 for Windows?
2001-04-06 21:28 Hao-yang Wang
@ 2001-04-06 21:59 ` Jerome Vouillon
0 siblings, 0 replies; 6+ messages in thread
From: Jerome Vouillon @ 2001-04-06 21:59 UTC (permalink / raw)
To: Hao-yang Wang; +Cc: caml-list
On Fri, Apr 06, 2001 at 02:28:41PM -0700, Hao-yang Wang wrote:
> >No, ocamldebug doesn't work on the "pure Win32" port of OCaml, while
> >it works (albeit a bit slowly) on the Cygwin port. And, yes, the Web
> >site should explain better the differences between these two ports.
>
> How difficult it would be to make ocamldebug work with the "pure Win32"
> port, without backstep and time travel?
I think that would be rather easy. In particular, you can already
turn off checkpointing (forks) using the command "set checkpoints off".
You loose a lot of functionalities, though...
-- Jerome
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-04-06 21:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 21:02 [Caml-list] Custom prettyprinter for polymorphic datatype John R Harrison
2001-03-27 8:44 ` Xavier Leroy
2001-04-05 8:07 ` [Caml-list] Does ocamldebug work for the non-cygwin version of Ocaml 3.01 for Windows? Mattias Waldau
2001-04-06 15:38 ` Xavier Leroy
2001-04-06 21:28 Hao-yang Wang
2001-04-06 21:59 ` Jerome Vouillon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox