Next Previous Up Top Contents Index

4.9 Inspecting values: the Inspector structure

addInspectMethod

Function

Structure

Shell.Inspector

Type

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

Syntax

addInspectMethod m -> ()

Arguments

m
An ML function.

Values

()

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 2.0 - 29 Jul 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker