|
CS 15-212: Fundamental Principles of Computer Science II
|
Introduction to MLWorks
Outline
About MLWorks
Documentation for MLWorks
MLWorks at CMU
Using Emacs with MLWorks
Starting MLWorks
The Podium
Preferences
The Listener
The Error Browser
The Inspector
The Context Browser and The System Browser
The Stack Browser (Debugger)
The Breakpoint Manager and The Trace Manager
The History Window
MLWorks is an integrated development environment for the ML programming
language developed by Harlequin Incorporated. MLWorks features a graphical
user interface, an interpreter, a debugger, browsers for various system
resources, and a compilation manager for projects with multiple source files.
The purpose of this document is to minimize the amount of time you
spend wrestling with the peculiarities of the environment, as opposed to the
more conceptual aspects of the assignments.
- Only available for Sun SPARCstations
- Available for Solaris operating systems:
- Solaris:
/afs/andrew.cmu.edu/scs/cs/15-212-X/bin/mlworks
- Use Sparc-5 or UltraSparc workstations in Andrew clusters:
Cluster | Sparcs |
WeH 5201 | 56 |
Morewood Gardens | 7 |
Hunt Library 2nd Floor | 6 |
- Use Sparc servers remotely by
telnet sun4.andrew.cmu.edu
- From a Sparc workstation in an Andrew cluster:
/afs/andrew.cmu.edu/scs/cs/15-212-X/bin/mlworks &
- From any workstation running the X-window system:
telnet sun4.andrew.cmu.edu
Enter user id and password
On your workstation:
xhost + unixn.andrew.cmu.edu
, where
unixn
is the server you were connected to.
On the server:
/afs/andrew.cmu.edu/scs/cs/15-212-X/bin/mlworks &
- Make a link to your local
bin
directory to save typing:
ln -s /afs/andrew.cmu.edu/scs/cs/15-212-X/bin/mlworks ~/bin/mlworks
rehash
mlworks &
- Note:
mlworks
is a version of mlworks
that automatically includes the SML Basis Library
Parts of the Basis Library will be used in the assignments
- Podium appears when MLWorks is starts up
- Text area shows "important" system messages
- Can't type into text area
- Can set preferences and bring up other tools
- Interrupt button suspends current computation
- Mode Preferences
- Choose SML '96
- Turn off Optimizing while debugging
- Turn on Debugging unless timing
- Editor Preferences
- Choose Emacs Server
- The User's Guide tells how to configure other editors
- General/Miscellaneous Preferences
- Select all options here
- Can turn off Use error browser to get
in-line error messages
- Compiler Details
- While debugging: turn on first set, turn off second set
- For timing: turn off first set, turn on second set
- Language Details
- Turn off all options here
- Save Preferences retains preferences for the next session
- Some preferences are only mentioned in the library documentation in the
Reference Manual
- An interactive dialogue with SML
- Text Area
- Type expressions and declarations into text area
Listener
MLWorks> 3+4;
val it : int = 7
MLWorks> val seven = 7;
val seven : int = 7
- MLWorks responds with type and value or error message
MLWorks> fun inc n = n+1;
val inc : int -> int = fn
MLWorks> val bogus = nothing;
Close
Line 1: error: Unbound value nothing
- Expressions are implicitly bound to
it
MLWorks> val pi = 3.14159;
val pi : real = 3.14159
- Each item must be terminated by a semicolon
MLWorks> val yes = true
... no response ...
;
val yes : bool = true
- Multi-line items are allowed
MLWorks>
fun factorial 0 = 1
| factorial n = n*(factorial (n-1));
val factorial : int -> int = fn
- Tab completes declaration names
MLWorks> fac
Tab
;
- Put cursor on a previous line to repeat it
- Emacs key sequences are supported
- Buttons
- Evaluate terminates current item
MLWorks> factorial 10;
Evaluate
val it : int = 3628800
- Step evaluates and invokes debugger
MLWorks> factorial 3;
Step
Debugger window appears
Step 4 times
Abort
val it : int = 6
- Time evaluates and reports execution time
MLWorks> factorial 10;
Time
val it : int = 3628800
0.06 (user: 0.04, system: 0.02, gc: 0.00)
- Clear erases current item
MLWorks> erase me
Clear
- Clear All erases text area
- Abandon cancels current item without clearing it
MLWorks> don't do this
Abandon
- Previous and Next step through
history of prior items
- File menu
- Save Source dumps all top-level declarations to a text file
Save Source As...
mystuff.sml
OK
- Use File... reads a source file into the
top-level
Use File...
mystuff.sml
OK
val it : unit = ()
...
- Use Use File... with an external editor
to develop assignments
- Other items are used for multi-file projects
- Edit menu
- Use Copy and Paste to
save typing
- Paste is only enabled for terminal inertion point
- Use Find... to locate library objects
Find...
Check all boxes
stream
Cancel
- View menu
- Controls how values are printed
- Can be used to look at contents of function values--
useful with programming with higher-order functions
- Action menu operates on most recent function or value
- History menu provides random access to prior items
- Appears when malformed program text is encountered
-- Emacs --
not a valid SML declaration
Ctrl-x Ctrl-w badstuff.sml
-- MLWorks --
Use File...
badstuff.sml
Close
Line 1: error: Unbound value a
- Can report syntax errors or type errors
-- Emacs --
val invalid = false+4
Ctrl-x Ctrl-s
-- MLWorks --
Use File...
badstuff.sml
Close
Line 1: error: Function applied to argument of
wrong type
- Upper pane lists errors for a given item
Lower pane provides details
- Double-click list item to select erroneous text in Emacs
Use File...
badstuff.sml
Double-click Line 1: ...
- Redo recompiles code after a fix
-- Emacs --
val valid = 3+4
Ctrl-x Ctrl-s
-- MLWorks --
Redo
val valid : int = 7
- Can be turned off to get traditional error messages
Uncheck Use error browser in
General Preferences
- Shows the type and contents of values in detail
MLWorks> (true, "wombat", [[1], [1+1, 2], [1+1+1, 1+2, 3]]);
val it : (bool * string * int list list) =
(true, "wombat", [[1], [2, 2], [3, 3, 3]])
Inspect
- Remembers original source code for a given value
Notice that the strings in Source and
Value are different
- Double-click items in Components area to show
their structure
Double-click (true, "\...", [...])
Double-click [[...], [...], [...]]
- Auto Selection inspects each value as it is entered into
the Listener
Auto Selection
MLWorks> (1, "two", 3.0);
val it : (int * string * real) = (1, "two", 3.0)
Double-click (1, "\...", 3.0)
Close
- View menu controls how values are displayed
- Context Browser shows declarations that you have
entered, plus the SML Basis Library
Context Browser
- System Browser shows declarations that are provided by
MLWorks
System Browser
- Behavior of browsers is otherwise identical
- Context Browser is a good way to find library
declarations
Context Browser
Double-click Math
Double-click String
Double-click TextIO
- Selection field saves typing for nested structure
components
Click val output: (outstream * string) -> unit
Double-click Selection field
Copy
MLWorks>
Paste
;
val it : (TextIO.StreamIO.outstream ref * string) -> unit =
fn
- Inspect opens the Inspector on a selected declaration
- Filters... controls which kinds of declarations are
displayed
- System Browser is a good way to find pervasive identifiers
- Turn on debugging and turn off optimization before using the Debugger
- Appears when a run-time error occurs, or when a breakpoint is
encountered
MLWorks> hd []:int list;
Abort
- Error Browser reports compile-time errors;
Stack Browser reports run-time errors
MLWorks> 1 div false;
Close
Line 1: error: Function applied to argument of
wrong type
MLWorks> 1 div 0;
Abort
- Compile-time errors are more common in SML and are usually easier to fix
- Top-most field shows reason for halt
MLWorks> fun divide(n, m) = n div m;
val divide : (int * int) -> int = fn
MLWorks> fun badnews q = divide(q, 0);
val badnews : int -> int = fn
MLWorks> badnews 11;
- Local variables shows variables in scope of suspended
functions
- Stack (grows upwards) shows suspended functions
- Select items in Stack to change items in
Local variables
Click badnews 11
- Abort aborts the computation in progress
Abort
- Continue resumes the computation in progress
- Step continues for one function call
- Next continues until the current function returns
- Continue, Step, and Next
are only enabled for breakpoints
- Breakpoint Manager is a list of functions that will
invoke the debugger
Breakpoint Manager
OK
- Trace Manager is a list of functions that will
trace their execution
MLWorks> divide;
val it : (int * int) -> int = fn
Trace
Trace Manager
OK
MLWorks> divide(47, 11);
divide (47, 11)
divide returns 4
val it : int = 4
MLWorks> divide;
val it : (int * int) -> int = fn
Untrace
- Behavior of managers is otherwise identical
- Add Name adds a function to the
breakpoint/trace list
Breakpoint Manager
divide
Add Name
OK
MLWorks> divide(47, 11);
Continue
val it : int = 4
- Delete Name removes a function from the
breakpoint/trace list
Breakpoint Manager
divide
Delete Name
Doesn't seem to work...
- Delete All disables breakpoints/tracing for all
functions
Delete All
OK
- History Window is a list of all declarations that have
been seen accepted by any Listener
History
- Note that the SML Basis Library is also visible here
- Remove Duplicates deletes all declarations that
have been shadowed by new declarations
Remove Duplicates
Andrew Bernard