
4.9 Inspecing values: the Inspector structure
Shell.Inspector
val addInspectMethod: ('a -> 'b) -> unit
unit
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.
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>
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>
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>

Generated with Harlequin WebMaker