180 likes | 278 Views
CS5205: Foundation in Programming Languages Lecture 0 : Overview. “Language Foundation, Extensions and Reasoning. Lecturer : Chin Wei Ngan Email : chinwn@comp.nus.edu.sg Office : COM2 4-32. Course Objectives. - graduate-level course with foundation focus
E N D
CS5205: Foundation in Programming LanguagesLecture 0 :Overview “Language Foundation, Extensions and Reasoning Lecturer : Chin Wei Ngan Email : chinwn@comp.nus.edu.sg Office : COM2 4-32 Introduction
Course Objectives - graduate-level course with foundation focus - languages as tools for programming - foundations for reasoning about programs - explore various language innovations Introduction
Course Outline • Lecture Topics (13 weeks) • Advanced Typed Language (Haskell) • http://www.haskell.org • Lambda Calculus (Core Language) • Interpreters • Untyped Scripting Language (Python) • http://www.python.org • Type System for Lightweight Analysis • http://www.cs.cmu.edu/~rwh/plbook/book.pdf • Semantics Introduction
Administrative Matters - mainly IVLE - Reading Materials (mostly online): www.haskell.org Robert Harper : Foundations of Practical Programming Languages. Free PL books : http://freeprogrammingbooks.com - Lectures + Assignments + Paper Reading+ Exam - Assignment/Project (35%) - Paper Reading (10%) - Quiz (10%) - Exam (45%) Introduction
Paper Presentation • Focus on Language Innovation/Application • Select A Paper (Week 2) • Give Presentation (Week 4/5) • Possible Topics • Concurrent and MultiCore Programming • Software Transaction Memory • GUI Programming • Testing with QuickCheck • IDE for Haskell • SELinks (OCaml) • etc • A List of Papers/Conferences will be given next week. Introduction
Assignments/Project (35%) • Small Exercises • Mini-Project • List of possible projects (Week 5) • Your own project • A useful tool • Use advanced languages, such as • Haskell, Ocaml, F#, Python, Boo, etc • Evaluation • (i) presentation/demo • (ii) draft report/paper Introduction
Why Study Foundations of PL? • Language used to organize programming thoughts. • Language can describe and organize computation. • Language features affect how ideas are expressed. • Foundation needed to support the design of good language features Introduction
Benefits of Good PL Features • Readability • Extensible Software. • Modifiability. • Reusability. • Correctness. Introduction
Benefits of Studying Foundations of PL • Design new languages for your work/research? • Inside any successful software system is a PL • Emacs : Elisp • Word, PPT : VBScript • Quake : QuakeC • Facebook : FBML, FBJS • Twitter : Ruby on Rails/Scala • Also: Latex, XML, SQL, PS/PDF Introduction
Benefits of Studying Foundations of PL • Different language paradigm can support different approaches to a given problem. • Can choose a solution that is best (or good enough) for the given problem. • PL is the primary tool of choice for programmers. If properly selected, it can amplify your programming capability. • Era of domain-specific programming languages. Introduction
Many Dimensions of PL • Syntax – verbose vs succint. prefix vs distfix. • Computational model : functional, imperative, OO or constraint-based. • Memory Model : explicit deallocation, garbage collection or region-based. • Typing : static vs dynamic typing; strong vs weak typing. • Execution Model : compiled (C/C++), interpreted (Perl), hybrid (Java). • Scoping : static vs dynamic scoping. Introduction
Advanced Language - Haskell • Strongly-typed with polymorphism • Higher-order functions • Pure Lazy Language. • Algebraic data types + records • Exceptions • Type classes, Monads, Arrows, etc • Advantages : concise, abstract, reuse • Why use Haskell ? cool & greater productivity Introduction
Some Applications of FP/Haskell • Hoogle – search in code library • Darcs – distributed version control • Programming user interface with arrows.. • How to program multicore? • map/reduce and Cloud computing • Bioinformatics • Cryptography Introduction
type is : (a b) (List a) (List b) Example - Haskell Program • Apply a function to every element of a list. • data List a = Nil | Cons a (List a) • map f Nil = Nil • map f (Cons x xs) = Cons (f x) (map f xs) a type variable map sqr(Cons 1 (Cons 2 (Cons 3 Nil))) ==> (Cons 1 (Cons 4 (Cons 9 Nil))) Introduction
Example - Haskell Program • Built-in List Type with syntactic sugar • data [a] = [] | a:[a] • map :: (a b) [a] [b] • map f [] = [] • map f (x:xs) = (f x):(map f xs) map sqr 1:(2:(3:[])) ==> 1:(4:(9:[])) map sqr [1,2,3] ==> [1,4,9] Introduction
Paradigm : Functional Expression • Problem : sum the square of a list of numbers • sumsq [1,2,3,4] = 1*1 +2*2 +3*3 + 4*4. • Problem : sum the square of a list of numbers • sumsq [] = 0 • sumsq (x:xs) = (sqr x) + (sumsqxs) Introduction
Paradigm : Imperative Loop • Problem : sum the square of a list of numbers • sumsq [1,2,3,4] = 1*1 +2*2 +3*3 + 4*4. • In F# (Ocaml dialect) • sumsq :: [Int] = Int • sumsqxs = let s = ref 0 in • for x in xs • s := !s + x ; • s Introduction
Paradigm : Function-Level Composition • Sum a list: sum [] = 0 sum (x:xs) = x + (sum xs) • Square a list: square xs = map sqr xs • Sum a square of list: square = sum o (map sqr) square = (map sqr) | sum square xs = xs |> (map sqr) |> sum Introduction