alice
library
manual.

Alice Project

The Print structure


________ Synopsis ____________________________________________________

    signature PRINT
    structure Print : PRINT

This structure provides generic printers for values and types. It is solely intended as a debugging aid.


________ Import ______________________________________________________

    import structure Print from "x-alice:/lib/system/Print"
    import signature PRINT from "x-alice:/lib/system/PRINT-sig"

In the interactive toplevel the functions printVal and printType are available unqualified.


________ Interface ___________________________________________________

    signature PRINT =
    sig
	val depth :       int ref
	val width :       int ref
	val layoutWidth : int ref

	val printVal :   'a -> unit
	val printType :  'a -> unit
	val outputVal :  TextIO.outstream * 'a * int -> unit
	val outputType : TextIO.outstream * 'a * int -> unit

	exception Type
	val register :   ('a -> string) -> unit
    end
  

________ Description _________________________________________________

exception Type

Raised by function register when the passed printer does not operate on a suitable abstract type.

depth
width

Control up to which depth and width nested and aggregated data structures are printed by printVal. Sub-structures beyond the depth limit are output as _, items of collections (e.g. lists) beyond the width limit are abbreviated to ... in the output.

layoutWidth

Controls the width of the layout as performed by printVal and printType, i.e. the maximum number of characters on each line.

outputVal (strm, x, w)
printVal x

Pretty prints the value x to the stream strm in ML syntax. If the output exceeds w characters, output is broken into multiple lines appropriately.

The second form is equivalent to:

      outputVal (TextIO.stdOut, x, !printWidth)
outputType (strm, x, w)
printType x

Pretty prints the type of value x to the stream strm in ML syntax. If the output exceeds w characters, output is broken into multiple lines appropriately.

The second form is equivalent to:

      outputType (TextIO.stdOut, x, !printWidth)
register f

Adds function f as a printer. The function must have a concrete type tyvarseq t -> string, where t has to be an abstract type. Further calls to outputVal use this function to transform values of any type tyseq t to a printable string representation. In the interactive toplevel, this also affects how evaluation results are printed. Raises Type if the type of f is not of the required form. This includes the case that t is not an abstract type, or that f is not fully polymorphic in the type arguments tyseq to t. Note that these rules also preclude f from being too polymorphic, i.e. being of type 'a -> string, because in that case no type name could be derived.



last modified 2007/Mar/30 17:10