Introduction to ML - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to ML

Description:

Title: CSE 341 Programming Languages Spring 1999 Author: Steven L. Tanimoto Last modified by: Steven Tanimoto Created Date: 3/28/1999 3:03:05 PM Document presentation ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 13
Provided by: Stev122
Category:

less

Transcript and Presenter's Notes

Title: Introduction to ML


1
Introduction to ML
  • History
  • Special features
  • Interacting with ML
  • MLs basic types
  • MLs composite types
  • Math. background for type description.

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, 1979. Mid 1980s
Standardization of 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.
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.
5
Sample Interactions
3 5 val it 8 int real(8) val it 8.0
real 8.0 real(1) val it 9.0 real
6
MLs 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
7
MLs 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.
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 S1 ? S2 ? ... ? Sn of
sets S1, S2, ..., Sn. Function A special kind of
binary relation.
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 Russells paradox.
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. D1 a, b, c C1
0, 1 B1 (a, 0), (a, 1), (c, 0), (c, 1) B1
is a binary with domain D1 and codomain
C1. Often, however, the domain and codomain are
identical. D2 C2 a, b, c B2 (a, a), (b,
b), (c, c), (a, c), (c, a) B2 is a binary
relation on D2.
11
Cartesian Product
A way to combine sets to get new sets. Let S1
a, b, c Let S2 1, 2 S1 ? S2 (a,1),
(a,2), (b,1), (b,2), (c,1), (c,2) A three-way
cartesian product S2 ? S2 ? S2 (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 (S2
? S2 ) ? S2 or S2 ? (S2 ? S2 ).
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.
Write a Comment
User Comments (0)
About PowerShow.com