1 / 72

Advanced Programming Languages

Advanced Programming Languages. Lecture 1 NCCU CS Dept. Fall 2005 Sept. 19, 2005. Topics. Haskell, Part 1 Lambda Calculus Operational Semantics Denotational Semantics Polymorphism & Type Inference Haskell, Pat 2 (Type classes, …) Subtyping and OO Research Papers. Reading Materials.

eris
Download Presentation

Advanced Programming Languages

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. Advanced Programming Languages Lecture 1 NCCU CS Dept. Fall 2005 Sept. 19, 2005

  2. Topics • Haskell, Part 1 • Lambda Calculus • Operational Semantics • Denotational Semantics • Polymorphism & Type Inference • Haskell, Pat 2 (Type classes, …) • Subtyping and OO • Research Papers

  3. Reading Materials • Lecture Notes from Prof. Johan Glimming • Haskell • Tutorial: A Gentle Introduction to Haskell • SML lecture notes • Other lecture notes • Textbooks: • B. Pierce, Type Systems and Programming Languages, MIT Press, 2002 • Nielson’s, Semantics with Applications, Draft, 2005 • Papers

  4. Haskell-based Textbooks • Simon Thompson. Haskell: The Craft of Functional Programming, Addison Wesley, 1999. • Richard Bird. Introduction to Functional Programming Using Haskell, second edition, Prentice Hall Europe, 1998. • Paul Hudak. The Haskell School of Expression, Cambridge University Press, 2000. • H. C. Cunningham. Notes on Functional Programming with Gofer, Technical Report UMCIS-1995-01, University of Mississippi, Department of Computer and Information Science, Revised January 1997. http://www.cs.olemiss.edu/~hcc/reports/gofer_notes.pdf

  5. Other FP Textbooks Of Interest • Fethi Rabhi and Guy Lapalme. Algorithms: A Functional Approach, Addison Wesley, 1999. • Chris Okasaki. Purely Functional Data Structures, Cambridge University Press, 1998.

  6. Programming Language Paradigms • Imperative languages • have implicit states • use commands to modify state • express how something is computed • include C, Pascal, Ada, … • Declarative languages • have no implicit states • use expressions that are evaluated • express what is to be computed • have different underlying models • functions: Lisp (Pure), ML, Haskell, …spreadsheets? SQL? • relations (logic): Prolog (Pure) , Parlog, …

  7. Orderly Expressions andDisorderly Statements Values ofxandydepend upon order of execution of statements x represents different values in different contexts

  8. Summary: Why Use Functional Programming? • Referential transparency • symbol always represents the same value • Equational reasoning (equals can be substituted by equals) • easy mathematical manipulation, parallel execution, etc. • Expressive and concise notation • Higher-order functions • take/return functions • powerful abstraction mechanisms • Lazy evaluation • defer evaluation until result needed • new algorithmic approaches • Polymorphic Type systems

  9. Why Teach/Learn FP and Haskell? • Introduces new problem solving techniques • Improves ability to build and use higher-level procedural and data abstractions • Helps instill a desire for elegance in design and implementation • Increases comfort and skill in use of recursive programs and data structures • Develops understanding of programming languages features such as type systems • Introduces programs as mathematical objects in a natural way

  10. Haskell: http://haskell.org/ • Haskell is a general purpose, purely functional programming language. • Started in 1987; current version Haskell 98 (2002 revised) • Yale Univ. & Glasgow Univ. • Chalmers Univ. (Sweden) • Many free implementations: • Hugs 98, a popular Haskell interpreter (written in C) • Derived from Gopher, by Mark Jones • GHC, the Glasgow Haskell Compiler • … • Good course websites: • http://csit.nottingham.edu.my/~cmichael/Teaching/Feb05/G51FUN/fun.html • http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/external.html

  11. Haskell Timeline Sept 87: kick off Apr 90: Haskell 1.0 Aug 91: Haskell 1.1 (153pp) May 92: Haskell 1.2 (SIGPLAN Notices) (164pp) May 96: Haskell 1.3. Monadic I/O, separate library report Apr 97: Haskell 1.4 (213pp) The Book! Feb 99: Haskell 98 (240pp) Dec 02: Haskell 98 revised (260pp)

  12. A Short Tour to Hugs

  13. Definitions • Definitions name :: type e.g.: size :: Int size = 12 - 3 • Function definitions name :: t1 -> t2 -> … -> tk -> t function name types of type of result arguments e.g.: exOr :: Bool -> Bool -> Bool exOr x y = (x || y) && not (x && y)

  14. Variable binders: x and y get their values from the argument

  15. (Integer  Integer)  Integer  Integer

  16. Technique: Accumulating parameter

  17. “==“

  18. Currying and Partial Evaluation add :: (Int,Int) -> Int add (x,y) = x + y ? add(3,4) => 7 ? add (3, ) => error add’ takes one argument and returns a function Takes advantage of Currying add' :: Int->(Int->Int) add' x y = x + y ? add’ 3 4 => 7 ? add’ 3 (add’ 3) :: Int -> Int (add’ 3) x = 3 + x ((+) 3)

  19. FoldRight Abstract different binary operators to be applied foldr :: (a -> b -> b) -> b -> [a] -> b foldr f z [] = z -- binary op, identity, list foldr f z (x:xs) = f x (foldr f z xs) sumlist :: [Int] -> Int sumlist xs = foldr (+) 0 xs concat' :: [[a]] -> [a] concat' xss = foldr (++) [] xss

  20. Using Partial Evaluation doublePos :: [Int] -> [Int] doublePos xs = map ((*) 2)(filter ((<) 0) xs) • Using operator section notation doublePos xs = map (*2) (filter (0<) xs) • Using list comprehension notation doublePos xs = [ 2*x | x <- xs, 0< x ]

More Related