cse 505 programming languages cse 505 programming
play

CSE 505: Programming Languages CSE 505: Programming Languages - PDF document

CSE 505: Programming Languages CSE 505: Programming Languages Instructor: Craig Chambers But if thought corrupts language , language can also TAs: Keunwoo Lee, Michael Ringenburg corrupt thought . A bad usage can spread by tradition and


  1. CSE 505: Programming Languages CSE 505: Programming Languages Instructor: Craig Chambers “But if thought corrupts language , language can also TAs: Keunwoo Lee, Michael Ringenburg corrupt thought . A bad usage can spread by tradition and imitation even among people who should and do know better.” Goals: George Orwell, Politics and the English Language, 1946 • study major concepts & design principles in programming languages • get practical experience using languages “If you cannot be the master of your language, you must be its embodying concepts & principles slave.” • gain reading-level understanding of formal semantics Richard Mitchell • be exposed to some current research “A different language is a different vision of life.” Why? Federico Fellini • understand the capabilities of modern programming language technology • understand how to exploit this technology in service of “The language we use ... determines the way in which we view more reliable, safer, more flexible systems and and think about the world around us.” more productive humans The Sapir-Whorf hypothesis Craig Chambers 1 CSE 505 Craig Chambers 2 CSE 505 Course outline Coursework Functional languages (e.g. ML , Scheme, Haskell) Functional & OO sections: • side-effect-free programming • 1-2 homeworks each • recursive first-class functions, recursive data structures • 1-2 programming projects each • algebraic data types, pattern-matching • 1 exam each • polymorphic static type systems & type inference Semantics section: Formal semantics • 1-2 homeworks • lambda calculus & extensions • 1 exam • static & dynamic (operational) semantics • key theorems, some proofs Final exam Object-oriented languages (e.g. Smalltalk, Self, Cecil/ Diesel ) • inheritance, subtype polymorphism • various models of dynamic dispatching • polymorphic static type systems Craig Chambers 3 CSE 505 Craig Chambers 4 CSE 505

  2. Language design goals Some target audiences Some end goals: Scientific, numerical computing • be easy to learn • Fortran, APL, ZPL • support rapid initial development • support easy maintenance, evolution Systems programming • encourage/guarantee reliability, safety • C, C++, Modula-3, ... • encourage/guarantee portability • allow/encourage efficiency Applications/symbolic programming • Java, C#, Lisp, Scheme, ML, Smalltalk, Cecil, Diesel, ... Some means to these goals: • readability Scripting, macro languages • writability • csh, Perl, Python, Tcl, Excel macros, ... • simplicity [but what does “simple” mean?] • expressiveness [but what does this mean?] Specialized languages • SQL, L A T E X , PostScript, Unix regular expressions, ... • fully-specified, platform-independent, safe semantics Many goals in conflict � language design is an engineering & artistic activity � need to consider target audience’s needs Craig Chambers 5 CSE 505 Craig Chambers 6 CSE 505 Some good language design principles Partial history of programming languages Fortran COBOL Lisp Strive for a simple, regular, orthogonal model 60 Algol 60 • for evaluation BASIC • for data reference • for memory management Fortran66 Simula67 E.g., be expression-oriented, reference-oriented 70 Pascal Prolog C Include sophisticated abstraction mechanisms, to define and name abstractions once, use many times Scheme Smalltalk • for control structures, data structures, types, ... Fortran77 SML 80 Include polymorphic static type checking E.g., with universal and existential subtype-bounded Ada quantification Common Lisp C++ Self Have a complete & precise language specification CLOS 90 Fortran90 • full run-time error checking for cases not detected statically HPF Cecil Java Domain-specific languages can exploit domain restrictions ZPL for better checking, expressiveness, performance GJ MultiJava 00 EML Cyclone C# Java 1.5 Diesel Craig Chambers 7 CSE 505 Craig Chambers 8 CSE 505

  3. ML Interpreter interface Salient features: Read-eval-print loop • functional • read input expression • functions are first-class values • reading ends with semi-colon (not needed in files) • = prompt indicates continuing expression on next line • largely side-effect free • strongly, statically typed • eval uate expression • polymorphic type system • print result • automatic type inference • repeat • expression-oriented, recursion-oriented • garbage-collected heap - 3 + 4; • pattern matching val it = 7 : int • exceptions - it + 5; • advanced module system val it = 12 : int • highly regular and expressive - it + 5; val it = 17 : int Designed as a M eta L anguage for automatic theorem proving system in mid 70’s by Milner et al. it variable (re)bound to last evaluated value, Standard ML: 1986 in case you want to use it again SML’97: 1997 Caml: a French version of ML, mid 80’s O’Caml: an object-oriented extension of Caml, late 90’s An interpreter is particularly useful during initial learning and debugging EML: a locally-developed OO extension of ML, 2002 Craig Chambers 9 CSE 505 Craig Chambers 10 CSE 505 Basic ML data types and operations Variables and binding Variables declared and initialized with a val binding: ML is organized around types - val x:int = 6; • each type defines some set of values of that type • each type defines a set of operations on values of that type val x = 6 : int - val y:int = x * x; int val y = 36 : int • ~ , + , - , * , div , mod ; = , <> , < , > , <= , >= ; real , chr Variable bindings cannot be changed! real • unlike assignment in C • ~ , + , - , * , / ; < , > , <= , >= (no equality); • like equality in math floor , ceil , trunc , round Variables can be bound again, bool : different from int but this shadows the previous definition • true , false ; = , <> ; orelse , andalso • e.g. it string Variable types can be omitted • e.g. "I said \"hi\"\tin dir C:\\stuff\\dir\n" • they will be inferred by ML based on the type of the r.h.s. - val z = x * y + 5; • = , <> , ^ val z = 221 : int char • e.g. #"a" , #"\n" • = , <> ; ord , str Craig Chambers 11 CSE 505 Craig Chambers 12 CSE 505

  4. Strong, static typing Type errors ML is statically typed : it will check for type errors statically Warning: type errors can look weird, since they use ML jargon: (i.e., when programs are entered, not when they’re run) - asd; • opposite extreme: dynamically typed Error: unbound variable or constructor: asd • blends also possible - 3 + 4.5; Error: operator and operand don’t agree ML is strongly typed : it catches all type errors (a.k.a. type safe ) operator domain: int * int [but which errors are classified as type errors?] operand: int * real • if not strongly typed, then weakly typed in expression: 3 + 4.5 - 3 / 4; Examples of other combinations? Error: overloaded variable not defined at type ←→ static dynamic symbol: / type: int ML strong weak Craig Chambers 13 CSE 505 Craig Chambers 14 CSE 505 Records More on records Can extract record fields using # fieldname function ML records are like C structs (like C’s -> operator, but a regular function) • allow heterogeneous field types, but fixed number of fields - val bob’ = {name= #name(bob), = age= #age(bob)+1}; A record type: {name:string, age:int} val bob’ = {age=21,name="Bob Smith"} : {...} • field order doesn’t matter (But wait for pattern-matching, a better way to access Unlike C, can write down a record value directly: components of records) {name="Bob Smith", age=20} Unlike C, can construct record values that have run-time Cannot assign to a record’s fields expressions specifying the field values • an immutable data structure {name = "Bob " ^ "Smith", age = 18+num_years_in_college} As with any other value, can bind record values to variables - val bob = {name="Bob " ^ "Smith", age=...}; val bob = {age=20,name="Bob Smith"} : {age:int,name:string} Orthogonality in action... Craig Chambers 15 CSE 505 Craig Chambers 16 CSE 505

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