This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 1 10/2/06 From slides by A. Dimock (Copyright) 1 DPL-4: Introduction to ML Material in these notes is adapted from materials by N. Ramsey, J. Ullman and A. Dimock. It should be considered as copyright by all of them. 10/2/06 From slides by A. Dimock (Copyright) 2 DPL-4: ML ML: designed for symbolic computation (including supporting the design of other languages: ML = Meta Language - initially, for a veri¡cation system). Observation: μ Scheme interpreter < 20% the size of C never an unexplained core dump and the interpreter rarely halts unexpectedly it thus provides lots of savings in error checking We want to extend this to functional programming, but detect errors as soon as possible (preferably at compile time!) We aim for: Scheme + pattern matching + static typing + exceptions. 10/2/06 From slides by A. Dimock (Copyright) 3 DPL-4: What's new with ML Real language means complexity: Core language: Pucella in 25 pages; Harper in 130 pages; Ullman in 250 pages. Language de¡nition: Milne, Tofte, Harper in 101 pages. Main areas of novelty: new syntax programming by pattern matching exceptions static polymorphic type inference Plus : very strong support for Abstract Data Types For now, we ignore "programming in the large". We'll be consumers of library routines, but not (yet) producers of modules. 10/2/06 From slides by A. Dimock (Copyright) 4 DPL-4: Starting ML One option: (on mercury.cs.uml.edu) $ mosml -P full- load "IO"; > val it = () : unit- ~3 + 5; > val it = 2 : int- quit(); (or ^D) Another option: $ sml /* download from www.smlnj.org */ …- ^D 10/2/06 From slides by A. Dimock (Copyright) 5 DPL-4: Basic values and expressions The arithmetic is "as usual" (in¡x), except that negative numbers are represented at input with ~ rather than - (~ is a unary operator, - is a binary one, and ML is a bit fussy, all in a good cause).- ~3 + 3; > val it = 0 : int ground types: int, real, string, char, unit, bool string concatenation with in¡x "hat": - "this"^" and that"; > val it = "this and that" : string true boolean types bool(true, false)- 3 < 4; > val it = true : bool 10/2/06 From slides by A. Dimock (Copyright) 6 DPL-4: Basic values and expressions, II Short circuit (= stop as soon as satis¡ed) andalso , orelse- (3 < 4) andalso (4 < 5); > val it = true : bool strings "as in C"; characters #"a", #"b", #"c", etc.; ' is "prime" or "tick mark" and is used in type variables (polymorphism??…) the language itself is completely expression based, like Scheme: if a then b else c is the same as C's a?b:c . Ex. of string and print formatting:- "A\tB\tC\n1\t2\t3\n"; > val it = "A\tB\tC\n1\t2\t3\n" : string- print("A\tB\tC\n1\t2\t3\n"); A B C 1 2 3 > val it = () : unit 2 10/2/06 From slides by A. Dimock (Copyright) 7 DPL-4: some typing observations ML is strongly typed - it does type inference for you, and provides error messages for mistyping…....
View Full Document
This note was uploaded on 02/13/2012 for the course CS 91.531 taught by Professor Giam during the Fall '09 term at UMass Lowell.
- Fall '09