4.9 Inspecing values: the Inspector structure

addInspectMethod

Function

Structure

Shell.Inspector

Type

val addInspectMethod: ('a -> 'b) -> unit

Syntax

addInspectMethod m -> ()

Arguments

m
An ML function.

Values

unit

Description

Adds the inspector method m to the inspector. An inspector method is a function of type t1 -> t2 that will be applied whenever an object of type t1 is being inspected. On subsequent inspection, values of type t1 are inspected as if they were of type t2.This function raises exception InspectError if m was not compiled with debugging information.

Example

First define the new datatype Foo as follows:

MLWorks> datatype Foo = FOO of int * bool;
datatype Foo =
  FOO of (int * bool)
val FOO : (int * bool) -> Foo
MLWorks> FOO (10, false);
val it : Foo = FOO (10, false)
MLWorks>

Using inspectIt returns the following result:

MLWorks> inspectIt();
Entering TTY inspector - enter ? for help
Value: FOO (10, false)
Type: Foo
1: 10
2: false
Inspector> q
val it : unit = ()
MLWorks>

Compare this output with the following output, resulting from inspecting Foo after adding a new inspector method using addInspectMethod:

MLWorks> fun inspectFoo (FOO (n,b)) = if b then {value = 0} else {value=n};
val inspectFoo : Foo -> {value: int} = fn
MLWorks> addInspectMethod (inspectFoo);
val it : unit = ()
MLWorks> FOO (10, false);
val it : Foo = FOO (10, false)
MLWorks> inspectIt();
Entering TTY inspector - enter ? for help
Value: FOO (10, false)
Type: Foo
value: 10
Inspector> q
val it : unit = ()
MLWorks>


MLWorks Reference Manual (version 1.0) - 3 DEC 1996

Generated with Harlequin WebMaker