CSE 341 -- S. Tanimoto Introduction to ML 1 Introduction to ML History Special features Interacting with ML ML’s basic types ML’s composite types Math.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

Functional Programming Lecture 10 - type checking.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Copyright © Cengage Learning. All rights reserved.
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Type Checking.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
1 Lecture 3 Topics –Languages –Language classes –Closure properties.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Composite types Cartesian products –tuples, records, structures disjoint unions –union, discriminated or variant records mappings –arrays, functions recursive.
Introduction to ML You will be responsible for learning ML on your own. Today I will cover some basics Read Robert Harper’s notes on “an introduction to.
Sets 1.
Sets 1.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
1 Functional Programming and ML. 2 What’s wrong with Imperative Languages? State State Introduces context sensitivity Introduces context sensitivity Harder.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
The Recursion Theorem Pages 217– ADVANCED TOPICS IN C O M P U T A B I L I T Y THEORY.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Basic Structures: Sets, Functions, Sequences, and Sums CSC-2259 Discrete Structures Konstantin Busch - LSU1.
April 14, 2015Applied Discrete Mathematics Week 10: Equivalence Relations 1 Properties of Relations Definition: A relation R on a set A is called transitive.
PZ03EX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03EX - ML Programming Language Design and Implementation.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
CompSci 102 Discrete Math for Computer Science
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University.
Section 2.1. Section Summary Definition of sets Describing Sets Roster Method Set-Builder Notation Some Important Sets in Mathematics Empty Set and Universal.
CSE 311 Foundations of Computing I Lecture 9 Proofs and Set Theory Autumn 2012 CSE
Homogeneous tuples What are they? –S 2 = S x S –S n = S x S x … x S Cardinalities –#(S 2 )= (#S) 2 –#(S n )= (#S) n –#(S 0 )= (#S) 0 =1 What is S 0 ? –It.
Chapter 2 With Question/Answer Animations. Section 2.1.
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Type Checking and Type Inference
ML: a quasi-functional language with strong typing
Representation, Syntax, Paradigms, Types
A lightening tour in 45 minutes
ML Programming Language Design and Implementation (4th Edition)
Representation, Syntax, Paradigms, Types
Functions, Patterns and Datatypes
Applied Discrete Mathematics Week 6: Relations/Digraphs
CSE S. Tanimoto Introduction to ML
ML’s Type Inference and Polymorphism
Representation, Syntax, Paradigms, Types
Functions, Patterns and Datatypes
CSE S. Tanimoto Introduction to ML
MCS680: Foundations Of Computer Science
ML’s Type Inference and Polymorphism
Representation, Syntax, Paradigms, Types
Mathematical Background
The Data Element.
Functions, Patterns and Datatypes
CSE S. Tanimoto Turing Completeness
CSE S. Tanimoto Introduction to ML
ML’s Type Inference and Polymorphism
The Data Element.
ML’s Type Inference and Polymorphism
CSE S. Tanimoto Introduction to ML
Functions, Patterns and Datatypes
Drew Wyborski Programming Languages
Presentation transcript:

CSE S. Tanimoto Introduction to ML 1 Introduction to ML History Special features Interacting with ML ML’s basic types ML’s composite types Math. background for type description.

CSE S. Tanimoto Introduction to ML 2 History Early 1970s: Design and implementation of ML by Milner, Morris, and Wadsworth at the Univ. of Edinburgh, Scotland. ML: Metalanguage of the Edinburgh LCF system. LCF = Logic for Computable Functions Gordon, Michael, Robin Milner, and Christopher Wadsworth. "Edinburgh LCF: A Mechanized Logic of Computation," Lecture Notes in Computer Science, Vol.78, Springer-Verlag, NY, Mid 1980s: Standardization of ML.

CSE S. Tanimoto Introduction to ML 3 Special Features A higher-order functional language. Statically type-checked, but polymorphic. Incorporates automatic type inference. Incorporates pattern matching. Garbage-collected. Has a formal semantics.

CSE S. Tanimoto Introduction to ML 4 Interaction with ML ML, like Lisp, provides a READ-EVAL-PRINT loop. Whenever ML prints the value of an expression, it also prints the TYPE of the value. ML keeps track of the types of variables and functions by solving systems of constraints. ML does not use assignment. On the other hand, it does use binding. Thus it uses the ‘=‘ sign in a mathematical sense. val flavor = "strawberry" ; binds a string to an identifier.

CSE S. Tanimoto Introduction to ML 5 Sample Interactions 3 * 5 ; val it = 8 : int real(8); val it = 8.0 : real real(1); val it = 9.0 : real

CSE S. Tanimoto Introduction to ML 6 ML’s Basic Types 3 * 5 ; val it = 8 : int 3.0 * 5.0 ; val it = 8.0 : real true ; val it = true : bool "rock" ^ "candy" ; val it = "rockcandy" : string #"a" ; val it = #"a" : char

CSE S. Tanimoto Introduction to ML 7 ML’s Composite Types Tuples: val mytuple = (26, "Oct.", 2001); val mytuple = (26, "Oct.", 2001) : int * string * int Each component can have a different type. Lists: [1, 2, 3] ; val it = [1, 2, 3] : int list ["nice"]; val it = ["nice"] : string list All components must have the same type.

CSE S. Tanimoto Introduction to ML 8 Math Background to Formal Representation of Types Set: a collection of items. Binary relation: a set of ordered pairs, whose elements come from a first set and a second set, which may be identical, partially overlapping, or disjoint. Cartesian product S 1  S 2 ...  S n of sets S 1, S 2,..., S n. Function: A special kind of binary relation.

CSE S. Tanimoto Introduction to ML 9 Set A collection of items. Must be well-defined, so that there is, in principle, a criterion that can be used to decide the membership of any item in the set. The set of all letters of the English alphabet. The set of all positive integers. NOT: The set of all sets that are not members of themselves. (SOASTANMOT). Is SOASTANMOT in SOASTANMOT? If so, then SOASTANMOT violates its own definition; if not,then it SHOULD be in SOASTANMOT. This is known as Russell’s paradox.

CSE S. Tanimoto Introduction to ML 10 Binary Relation A set of ordered pairs. First element comes from a set called the domain. Second element comes from a set called the codomain. D 1 = {a, b, c} C 1 = {0, 1} B 1 = {(a, 0), (a, 1), (c, 0), (c, 1)} B 1 is a binary with domain D 1 and codomain C 1. Often, however, the domain and codomain are identical. D 2 = C 2 = {a, b, c} B 2 = { (a, a), (b, b), (c, c), (a, c), (c, a)} B 2 is a binary relation on D 2.

CSE S. Tanimoto Introduction to ML 11 Cartesian Product A way to combine sets to get new sets. Let S 1 = {a, b, c} Let S 2 = {1, 2} S 1  S 2 = { (a,1), (a,2), (b,1), (b,2), (c,1), (c,2) } A three-way cartesian product: S 2  S 2  S 2 = { (1,1,1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1), (2,2,2) } This is not equivalent to (S 2  S 2 )  S 2 or S 2  (S 2  S 2 ).

CSE S. Tanimoto Introduction to ML 12 Function Function: A binary relation whose first components are from a set called the domain, and whose second components are from a set called the range, and such that each domain element is paired with one and only one range element. D = {a, b, c}; R = {0, 1} F = { (a,0), (b,0), (c,1)} is a function from D to R. F: D  R B = { (a,0), (a,1), (b,0), (c,0) } is not a function.