Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Languages winter term 2010/11

Similar presentations


Presentation on theme: "Programming Languages winter term 2010/11"— Presentation transcript:

1

2 Programming Languages winter term 2010/11
Jörg Kreiker, I2+I7

3 Getting started What is your favorite PL?
Do you know any functional language? Logic programming? Expectations? Implement the joke in your favorite PL

4 Popular languages: langpop.com

5 Most talked about languages

6 Meet Haskell: a straight bat
Download interpreter (hugs/ghci) and compiler (ghc) from haskell.org Pure, lazy, functional language Use declarative languages only As opposed to imperative Freely available books and tutorials Printing 500 lines in Haskell

7 Haskell.org

8 realworldhaskell.org

9 Organization Lectures: Thursday, 12 noon – 1.30pm, 00.08.038
Mostly theory Tutorials: Thursday, 2pm-3.30pm, tbd First tutorial: next week Mostly programming Online problem solving Discussion and comparison of languages and paradigms Website: www2.in.tum.de/hp/Main?nid=142

10 Grading Written exam, 40 points, 90 minutes Programming project “Exen”
Implement a Haskell interpreter in Haskell Earns you up to 4 bonus points Due before xmas “Exen” Small tests during tutorials Earn you 1 (>50%) or 2 (>75%) bonus points

11 Code of conduct Interaction, interaction, interaction
Buzz votes and polls Ask questions (English or German) No cell phones, no eating 1 or 2 breaks of 5-10 minutes per lecture Laptops for online programming Coffee is fine

12

13 Learning goals

14 1 To write short error-free programs, without testing, for tasks such as binary search, and to use a formal system such as Hoare logic to verify them.

15 2 To use language features such as higher-order functions and continuations to implement tasks such as backtracking and memoization.

16 Some modern features and techniques
Continuations Polymorphism First-class functions (closures, lambda) Pattern matching Software transactional memory Memoization and backtracking Exceptions Monads

17 3 To write concurrent programs using shared variables or message-passing, and to give rigorous informal arguments for their lack of errors.

18 4 To specify precisely and implement correctly a simple programming language.

19 5 To estimate the time and space requirements of basic operations on widely used data representations.

20 6 To write a clear and error-free program of sufficient complexity – say a syntax-directed editor – that it must be structured carefully.

21 Content Haskell Prolog Laziness State I/O Continuations
Lambda calculus Types and semantics Prolog Programming by search Backtracking

22 Clarify and define formally…
Syntax vs semantics Types Scope and binding Functions vs procedures Call-by-value, call-by name, call-by need Identifiers vs variables State Modularity Polymorphism

23

24 The factorial function
П fac(n) = i=1 n i implement the factorial function in your favorite language discuss with your neighbor 3 minutes

25 Haskell freshman fac n = if n == 0 then 1 else n * fac (n-1)

26 Haskell sophomore fac = \n -> if (==) n 0 then 1
else (*) n (fac ((-) n 1))

27 Haskell junior fac 0 = 1 fac n = n * fac (n-1)

28 Haskell senior fac n = foldr (*) [1..n] fac n = foldl (*) [1..n]

29 Memoizing Haskell programmer
facs n = scanl (*) 1 [1..] fac n = facs !! n

30 Continuation-passing style
facCPS k 0 = k 1 facCPS k n = facCPS (k . (n *)) (n-1) fac = facCPS id

31 Accumulating programmer
facACC a 0 = a facACC a n = fac (a*n) (n-1) fac = facACC 1

32 Haskell boy scout y f = f (y f) fac = y (\f n -> if n==0 then 1
else n * f (n-1))

33 Pure madness s f g x = f x (g x) k x y = x b f g x = f (g x)
c f g x = f x g y f = f (y f) cond p f g x = if p x then f x else g x fac = y (b (cond ((==) 0) (k 1)) (b (s (*)) (c b pred)))

34

35 Conclusion Learning goals, organization, content Haskell primer
Currying Pattern matching List combinators (foldr, foldl, scanl) Iteration vs recursion Accumulators and tail calls Continuations S, K, B, C, Y combinators

36 Outlook Next time: more on Haskell Lists and trees Types
More language features


Download ppt "Programming Languages winter term 2010/11"

Similar presentations


Ads by Google