Re: how to invoke SML/NJ's built-in pretty printer from a program?
John Reppy <[email protected]> Thu, 26 Feb 2009 08:18:54 -0600
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
I don't think that what you want is possible in SML/NJ, since it = requires runtime type information. In the REPL, we are able to pretty-print = results because we know their type, but that is not true in general. Sorry. - John On Feb 26, 2009, at 7:10 AM, Joe Wells wrote: > SML/NJ has a built-in pretty printer for printing values of various > types used by the top-level REPL. > > How do I invoke it from a program? > > There is a function PrettyPrint.pp_to_string of type int -> (stream -> > 'a -> unit) -> 'a -> string, but to use it I would have to give it a > value of type (stream -> 'a -> unit). How do I construct this > argument? > > To make my question concrete, in the following SML program, by what do > I replace =93magic_pretty_printer=94 to make the program print =93Happy, > happy, joy, joy!=94? > > datatype Xyzzy =3D C of Xyzzy * Xyzzy | D of string > > val plugh =3D C (D "hello",D "sailor") > val plugh_string =3D "C (D \"hello\",D \"sailor\")" > > if ((magic_pretty_printer plugh) =3D plugh_string) > then (print "Happy, happy, joy, joy!\n") > else (raise (Fail "magic pretty printer gave wrong result")) > > I've browsed around the source for a while and failed to find what I > need. Any hints would be helpful. > > I'd rather not use Backend.Interact.evalStream and capture the output > somehow, but if that is my only option I would be grateful for an > example of how to do it. > > Thanks for your time in considering this question. > > -- = > Joe > > > -- = > Heriot-Watt University is a Scottish charity > registered under charity number SC000278. > > > -------------------------------------------------------------------------= ----- > Open Source Business Conference (OSBC), March 24-25, 2009, San = > Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the = > Enterprise > -Strategies to boost innovation and cut costs with open source = > participation > -Receive a $600 discount off the registration fee with the source = > code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Smlnj-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/smlnj-list ---------------------------------------------------------------------------= --- Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H