ML - The ML Language Typed Functional Programming with...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
cs3723 1 The ML Language Typed Functional Programming with Assignments
Background image of page 1

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

View Full DocumentRight Arrow Icon
cs3723 2 A Piece of History Algol 60 Algol 68 Pascal ML Modula Lisp
Background image of page 2
cs3723 3 The Algol Family--- Imperative Programming Modify machine states through statements Block of statements, separated by semicolon Begin … End (Algol, Pascal), { … } in C Conditionals and loops Recursive functions using stack storage management Parameter passing by value/reference by name works well only for functional languages Rich and structured type system Basic types: int, char, string, complex, bit, … Compound types: record, struct, union/variant, range, array, pointer, procedure Representative languages Algol60, Algol68 (general purpose) Pascal (academic teaching) C (Unix Operating system)
Background image of page 3

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

View Full DocumentRight Arrow Icon
cs3723 4 ML: Typed Functional Programming Language Developed by Robin Milner et al. Meta-language for Logic for Computable Functions Both compiled and interpreted; intended for interactive use Typed functional programming language Every expression is allowed to have a single type; types of expressions checked at compile time Combination of Lisp and Algol-like features Expression-oriented Higher-order functions Garbage collection Abstract data types Module system Exceptions Sound and expressive type system If a function f has type A B , then for every x in A , If f(x) terminates without raising exceptions, then it has type B . Allows parametric types for functions and compound data structures Support union of different types Compiler automatically infers variable types before executing Type system does not allow casts or other loopholes
Background image of page 4
cs3723 5 ML Atomic Values Basic types () : unit true/false : bool 3 : int “ab” : string 3.0 : real Special operations (infix notation) For bool: andalso orelse not For int: + - * div For string: ^ (concatenation) For real: + - * / Explicit type conversion real(3) 3.0 : real
Background image of page 5

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

View Full DocumentRight Arrow Icon
cs3723 6 ML Compound Values List nil : ‘a list, [] : ‘a list, [“a”, “b”] : string list, [7] : int list Elements must have the same type; ‘a: type parameter Operators: null (null?), hd (car), tl (cdr), :: (cons) Tuple (3, 4, “abc”) : int * int * string Operators: #2(3, 4, “abc”) ==> 4 : int Record {First = 3, Second = “my”} : {First:int, Second: string} Operators: #First{First = 3, Second = “my”} ==> 3 : int Reference cell (assignable variable) ref 3 : int ref Operators: !(ref 3) ==> 3 : int Function abstraction fn x => x + 5 : int int; fun add5(x) => x + 5 : int int Function application: (fn x => x + 5) 3 ==> 8 : int; add5(3)==>8 Datatypes (user-defined types) datatype tree = LEAF of int | NODE of tree*tree LEAF(3) : tree
Background image of page 6
cs3723 7 ML Pattern-based Declarations ML pattern <pattern> ::= <value> | <var>
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/13/2009 for the course CS 3773 taught by Professor Staff during the Spring '08 term at The University of Texas at San Antonio- San Antonio.

Page1 / 26

ML - The ML Language Typed Functional Programming with...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online