1 / 12

Introduction to ML

Introduction to ML. History Special features Interacting with ML ML’s basic types ML’s composite types Math. background for type description. History. Early 1970s: Design and implementation of ML by Milner, Morris, and Wadsworth at the Univ. of Edinburgh, Scotland.

gisela
Télécharger la présentation

Introduction to ML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to ML • History • Special features • Interacting with ML • ML’s basic types • ML’s composite types • Math. background for type description. CSE 341 -- 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, 1979. Mid 1980s: Standardization of ML. CSE 341 -- 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 341 -- 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 341 -- S. Tanimoto Introduction to ML

  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 CSE 341 -- 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 341 -- 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 341 -- 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 S1 S2 ...  Sn of sets S1, S2, ..., Sn. Function: A special kind of binary relation. CSE 341 -- 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 341 -- 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. 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. CSE 341 -- S. Tanimoto Introduction to ML

  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 ). CSE 341 -- 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. CSE 341 -- S. Tanimoto Introduction to ML

More Related