10 21 08
play

10/21/08 cs242 Lisp Algol 60 Algol 68 Pascal Kathleen Fisher ML - PDF document

10/21/08 cs242 Lisp Algol 60 Algol 68 Pascal Kathleen Fisher ML Modula Haskell Reading: Concepts in Programming Languages Chapter 5 except 5.4.5 Real World Haskell, Chapter 0 and Chapter 1


  1. 10/21/08 cs242 � Lisp � Algol 60 � Algol 68 � Pascal � Kathleen Fisher � ML � Modula � Haskell � Reading: “Concepts in Programming Languages” Chapter 5 except 5.4.5 � “Real World Haskell”, Chapter 0 and Chapter 1 � (http:/ /book.realworldhaskell.org/) � Many other languages: � Algol 58, Algol W, Euclid, EL1, Mesa (PARC), … � Modula-2, Oberon, Modula-3 (DEC) � Thanks to John Mitchell and Simon Peyton Jones for some of these slides. �  Basic Language of 1960 �  Simple imperative language + functions � real procedure average(A,n);  Successful syntax, BNF -- used by many successors � No array bounds. � real array A; integer n;  statement oriented �  begin … end blocks (like C { … } ) � begin  if … then … else � real sum; sum := 0;  Recursive functions and stack storage allocation � for i = 1 step 1 until n  Fewer ad hoc restrictions than Fortran � do  General array references: A[ x + B[3] * y ] sum := sum + A[i];  Type discipline was improved by later languages � No “;” here. � average := sum/n  Very influential but not widely used in US � end;  Tony Hoare: “Here is a language so far ahead of its time that it was not only an improvement on its predecessors Set procedure return value by assignment. � but also on nearly all of its successors. ” �  Question: �  Holes in type discipline �  Parameter types can be arrays, but �  Is x := x equivalent to doing nothing? �  No array bounds �  Interesting answer in Algol: �  Parameter types can be procedures, but �  No argument or return types for procedure parameters � integer procedure p;  Problems with parameter passing mechanisms � begin ….  Pass-by-name “Copy rule” duplicates code, p := p interacting badly with side effects � ….  Pass-by-value expensive for arrays � end;  Some awkward control issues �  goto out of block requires memory management � Assignment here is actually a recursive call! � 1

  2. 10/21/08  Substitute text of actual parameter  Considered difficult to understand �  Unpredictable with side effects!  Idiosyncratic terminology �  Types were called “modes” �  Example  Arrays were called “multiple values” �  Used vW grammars instead of BNF � procedure inc2(i, j);  Context-sensitive grammar invented by van Wijngaarden � integer i, j;  Elaborate type system � begin begin  Complicated type conversions � i := i+1; k := k+1; j := j+1 A[k] := A[k] +1  Fixed some problems of Algol 60 � end; end;  Eliminated pass-by-name � inc2 (k, A[k]);  Not widely adopted � Is this what you expected? � Adr Adriaan aan v van an Wijn jngaa aarden den �  Primitive modes �  Compound modes �  Storage management �  int �  arrays �  Local storage on stack �  real �  structures �  char �  Heap storage, explicit alloc, and garbage collection �  procedures �  bool �  sets �  Parameter passing �  string �  pointers �  compl (complex) �  Pass-by-value �  bits �  Use pointer types to obtain pass-by-reference �  bytes �  sema (semaphore) �  Assignable procedure variables � Rich, structured, and  format (I/O) � orthogonal type system is  Follow “orthogonality” principle rigorously �  file � a major contribution of Algol 68. A Tutorial on Algol 68 by Andrew S. Tanenbaum �  Designed by Niklaus Wirth (Turing Award) � illegal �  Array bounds part of type �  Revised the type system of Algol � procedure p(a : array [1..10] of integer)  Good data-structuring concepts � procedure p(n: integer, a : array [1..n] of integer)  records, variants, subranges �  Attempt at orthogonal design backfires �  More restrictive than Algol 60/ 68 � – Parameter must be given a type �  Procedure parameters cannot have procedure – Type cannot contain variables � parameters � How could this have happened? Emphasis on teaching? �  Popular teaching language �  Not successful for “industrial-strength” projects �  Simple one-pass compiler �  Kernighan: “Why Pascal is not my favorite language” �  Left niche for C; niche has expanded!! � Niklaus Wirth � 2

  3. 10/21/08 ML ML  Statically typed, general-purpose programming language �  Type safe! � Designed by Dennis Ritchie, Turing Award winner, for writing Unix �  Intended for interactive use �  Combination of Lisp and Algol-like features �  Evolved from B, which was based on BCPL �  Expression-oriented �  B was an untyped language; C adds some checking �  Higher-order functions �  Garbage collection �  Relationship between arrays and pointers �  Abstract data types �  An array is treated as a pointer to first element �  Module system �  Exceptions �  E1[E2] is equivalent to ptr dereference: *((E1)+(E2))  Pointer arithmetic is not common in other languages �  Designed by Turing-Award winner Robin Milner for LCF Theorem Prover �  Ritchie quote �  Used in textbook as example language �  “C is quirky, flawed, and a tremendous success. ” � Hask Ha skel ell  Haskell is a programming language that is �  Good vehicle for studying language concepts �  Similar to ML: general-purpose, strongly typed, higher-order, functional, supports type inference, supports interactive and  Types and type checking � compiled use �  General issues in static and dynamic typing �  Different from ML: lazy evaluation, purely functional, rapidly  Type inference � evolving type system. �  Parametric polymorphism �  Designed by committee in 80’ s and 90’ s to unify  Ad hoc polymorphism � research efforts in lazy languages. �  Control �  Haskell 1.0 in 1990, Haskell ‘98, Haskell’ ongoing. �  Lazy vs. eager evaluation �  “A History of Haskell: Being Lazy with Class” HOPL 3 �  Tail recursion and continuations �  Precise management of effects � Paul Hudak � Simon Peyton Jones � John Hughes � Phil Wadler � Practitioners �  Functional programming will make you think 1,000,000 differently about programming. �  Mainstream languages are all about state � 10,000  Functional programming is all about values �  Ideas will make you a better programmer in 100 whatever language you regularly use. � Geeks � The quick death � 1  Haskell is “cutting edge. ” A lot of current research is done in the context of Haskell. � 1yr 5yr 10yr 15yr 3

  4. 10/21/08 Threshold of immortality � Practitioners � Practitioners � 1,000,000 1,000,000 10,000 10,000 The complete absence of death � 100 100 The slow death � Geeks � Geeks � 1 1 1yr 5yr 10yr 15yr 1yr 5yr 10yr 15yr “Learning Haskell is a great way of training yourself to think functionally so you are ready to take full advantage of “I'm already looking at coding In Haskell, f :: A → B means for every x ∈ A, � C# 3.0 when it comes out” � Practitioners � problems and my mental (blog Apr 2007) � perspective is now shifting 1,000,000 back and forth between purely OO and more FP styled f(x) = some element y = f(x) ∈ B � solutions” � (blog Mar 2007) � run forever � 10,000 100 The second life? � In words, “if f(x) terminates, then f(x) ∈ B. ” � Geeks � In ML, functions with type A → B can throw an 1 exception, but not in Haskell. � 1990 1995 2000 2005 2010  Functions that take other functions as arguments or  Interactive Interpretor (ghci): read-eval-print � return as a result are higher-order functions. �  ghci infers type before compiling or executing �  Common Examples: � Type system does not allow casts or other loopholes! �  Map: applies argument function to each element in a collection. �  Examples �  Reduce: takes a collection, an initial value, and a function, and combines the elements in the collection according to the function. � Prelude> (5+3)-2 6 list = [1,2,3] it :: Integer r = foldl (\accumulator i -> i + accumulator) 0 list Prelude> if 5>3 then “Harry” else “Hermione” “Harry”  Google uses Map/Reduce to parallelize and distribute it :: [Char] -- String is equivalent to [Char] massive data processing tasks. Prelude> 5==4 False (Dean & Ghemawat, OSDI 2004) � it :: Bool 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend