{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

324-lecture12 - Principles of Programming Languages...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Principles of Programming Languages Principles of Programming Languages Lecture 12 Lecture 12 University of Toronto Wael Aboulsaadat Wael Aboulsaadat [email protected] [email protected] http://portal.utoronto.ca/ 1 ML: introduction ML: introduction • Developed at Edinburgh (early ’80s) as M eta- L anguage for a program verification system – Now a general purpose language – There are two basic dialects of ML • Standard ML (1991) & ML 2000 • Caml (including Objective Caml, or OCaml) • A pure functional language University of Toronto – Based on typed lambda calculus – Grew out of frustration with Scheme! – Serious programs can be written without using variables • Widely accepted – reasonable performance (claimed) – can be compiled – syntax not as arcane as Scheme 2 ML: main features ML: main features • Strong, static typing – Quite a fancy type system! • Parametric polymorphism – Similar to OOP ( in fact, it influenced OO ) • Pattern matching unction as a template University of Toronto – Function as a template • Exception handling – Allow you to handle errors/exception • Type inference • Recursive data type 3 ML: how far have PL advanced? ML: how far have PL advanced? • Writing a gcd implementation Pascal University of Toronto ( define gcd ( lambda (m n) ( if (zero? n) m (gcd n (remainder m n))))) Scheme fun gcd(m,n) = if m=0 then n else gcd(n mod m, m); ML 4 ML: types & expressions ML: types & expressions • Primitive types – bool, int, real, string • Complex types – list, tuple, array, record, function University of Toronto • Each ML expression has a type associated with it. – Interpreter builds the type expression for each input – Cannot mix types in expressions 2+3.0 b error! • Must explicitly coerce/type-case e.g. real(2) + 3.0 : real 5 ML: Primitive Types ML: Primitive Types • int e.g. x: int ; – Negative sign uses ~ – Operators: + - * div mod • real e.g. x: real ; – 3.45 or using e notation (3E7) – Operators: + - * / – Conversion functions: real(integer), floor(real), abs(x) University of Toronto • string e.g. s: string ; – Delimited by double quotes – Caret ^ is concatenation e.g. "house" ^ "cat" – Function size returns length of string – Special characters: \n \t \" \\ • bool e.g. b: bool ; – true (and false ) 6 ML: operators...
View Full Document

{[ snackBarMessage ]}

Page1 / 19

324-lecture12 - Principles of Programming Languages...

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

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