
 Com  Sci  221  _  Programming  Languages



        Using  Standard  ML  of  New  Jersey



   (by Steph Bailey, edited by Mike O'Donnell, Dec.  1994)

0.1      Working  the  Compiler



Once you have created your source program, using your favorite editor,

you would like to compile it and run it. This is accomplished by running

the ML program,  and then loading the file,  and then asking ML to

perform some task for you (much like LISP or Prolog systems).


Below is a sample ML session with my prop.sml program:
Sun3:  ml

Standard  ML  of  New  Jersey,  Version  0.24,  22  November  1988

val  it  =  ()  :  unit

-  use  "prop.sml";  (*  Load  prop.sml  *)

[opening  prop.sml]

datatype   truth

con  FALSE  :  truth

con  TRUE  :  truth

datatype   term

con  AND  :  term  *  term  ->  term

con  CON  :  truth  ->  term

con  NOT  :  term  ->  term

con  OR  :  term  *  term  ->  term

con  VAR  :  string  ->  term

val  negate  =  fn  :  term  ->  term

val  cnf  =  fn  :  term  ->  term

[closing  prop.sml]

val  it  =  ()  :  unit

-  cnf(OR(AND(VAR  "p",VAR  "q")),  VAR  "r"));  (*  Test  a  case  *)

val  it  =  AND  (OR  (VAR  #,VAR  #),OR  (VAR  #,VAR  #))  :  term

-  (*  #  means  that  there  is  more  to  the  list,  but  it  is  not  print*
 *ed  *)

-  (*  Now  set  the  magic  variable  to  the  whole  list  *)

-  System.Control.Print.printDepth:=  10;

val  it  =  ()  :  unit

-  cnf(OR(AND(VAR  "p",VAR  "q")),  VAR  "r"));  (*  Test  the  case  again  *)

val  it  =  AND  (OR  (VAR  "p",VAR  "r"),OR  (VAR  "q",VAR  "r"))  :  term

-  (*  This  time  it  printed  the  whole  list  *)

-  ^D



                                          1

Sun3:

0.2      Documentation



One of the easiest ways to learn a programming language is by example.

If you have many good examples, you often don't even need a text (at

least for basic language use). Fortunately, Standard ML of New Jersey

comes with a whole suite of interesting examples which can be found

in
           /usr/local/share/classes/cs221/examples
The prop.sml program I used above is just one of the many fine examples

to be found in this directory.


The reference manual for ML is in LATEX form in:
           /usr/local/share/classes/cs221/refman
There  are  a  number  of  .tex  files,  each  of  which  is  a  chapter  of  t*
 *he

reference manual. The easiest way to view these is to simply type them

out on the terminal, and ignore any funny stuff that you see in the files

(formatting commands).  Please don't print the reference manual out

because it is sure to be many pages which will just go to the recycling

bin shortly after you print it. I will print one copy for each of you early

in the quarter. For the small programs you write for class, you probably

won't need debugging tools.  In case you want to look into debugging

in ML, instructions are in /usr/local/share/classes/cs221/debug.


Unfortunately, the MacLab tutors are not well versed in ML, so your

best source of information is the instructor, or one of your fellow stu-

dents.   For  general  Unix  questions,  however,  the  tutors  are  usually

excellent sources of advice.


                                          2
