09 SML0 - SML Downloadfromhttp/www.smlnj.org...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
SML Download from  http://www.smlnj.org/ From wikipedia entry Standard ML (SML) is a general-purpose, modular, functional  programming language with compile-time type checking and  type inference.  It is popular among compiler writers and  programming language researchers, as well as in the  development of theorem provers SML is a modern descendant of the ML programming language  … It is unique among widely used languages in that it has a  formal specification, given as typing rules and an operational  semantics  in  The Definition of Standard ML  (1990, revised and  simplified as  The Definition of Standard ML (Revised)  in 1997). Read about the ML type system in Supplement to  Chapter 7. Links to several books and tutorials at the smlnj web site. 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
ML session seems like an interpreter  session (but really compiled) Terminate session with <eof> character  (cntr d on unix, cntr z on windows) Can create definitions in a file with any text  editor and read into your session with  function  use , which take a string  containing the file name as an argument use “mlprogram.sml”; For debugging, it is helpful if your editor  displays line numbers. 2
Image of page 2
Elements of ML  (incomplete) primitive types:    int, real,  char,  string,  bool 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
tuples:   (3,4): int * int, (“hello”, 4, 5):  string * int * int (“pi”, 3.14159): string * real 4
Image of page 4
lists [3,4]:  int list [“adios”, “goodbye”, “auf wiedersehen”]:  string list build list using  [] , the empty list, nil ::  , the cons operator, which makes a new list by putting  element in front of an existing list             4::[] = [4] 3::[4] = [3,4] 5
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
functions ML is  functional programming language: programs are functions (functions have types) running a program is evaluating an expression variables are like variables as in mathematics no assignment statement in a pure functional  language (although ML is not pure) no side effects in expressions 6
Image of page 6
val  z = 3; val  z = 3: int val  is the keyword to declare a new variable and  bind it to a value ;  tells interpreter to elaborate, compile, evaluate  and print results  (allows typing on multiple lines) blue lines are entered by the programmer red lines are the response by SML 7
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
val  z = 3; val z = 3: int z; val it = 3:int   (result of evaluating z wasn’t  bound to anything, ml binds it to “it”) it; val it = 3:int val y = z + 1; val y = 4: int y; val it = 4: int 8
Image of page 8
Redefining names (some output omitted) val z = 3; val y = z+1: int val z = 1; y; 4 IMPORTANT:  previous bindings don’t  change (ML doesn’t go back and reevaluate everything previously done) y is still 4, not recomputed with new value of  z to be 2 9
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern