CS 541 Lecture -*- Outline -*- * Introduction to the Declarative Paradigm ** Motivation *** review of the course plan "programming is too hard" Q: why? Special-purpose training not oriented to help end users conceptual gap caused by concern for efficiency Q: what approaches did we identify? Domains specific languages (Haskell) reuse/frameworks (OOP) executable specifications/search... *** programming is difficult, expensive Q: What are the steps in building a computer system to do some job? specifying what is to be done + detailed design and coding + maintenance (how does maintenance work?) Q: What steps cost the most? Q: Can we separate them? Which could we automate? yes, the detailed design and coding perhaps, if we could execute specifications *** rapid prototyping Q: How do we know if we're building the right system? the idea of rapid prototyping is to quickly turn around specifications into prototypes to "hone in" on the "right" system. Q: What would help us do that better? if we could execute specifications Q: What are the costs we care about in rapid prototyping? *** summary ------------------------------------------ MOTIVATIONS FOR DECLARATIVE PROGRAMMING GOALS OF DECLARATIVE PROGRAMMING ------------------------------------------ ** Goals Q: So what should our goals for declarative programming be, to solve the problems that motivate the paradigm? WRITE programs efficiently (vs. running efficiently) execute specifications, declarative (what, not how) -only state constraints on result e.g., x is-in l if x is the head of l x is-in l if x is-in the tail of l -no explict (or separate) directions about data structures, algorithms ** Orientation (reminder) Q: How would you classify this kind of programming language, versus the others you know about? Q: What are the categories of programming languages? Two basic styles of programming (there are other dimensions...) *draw Venn diagram before class* *** Procedural **** Imperative or von Neumann (mutation, assignment) Algol 60, Pascal, Ada, Smalltalk **** Applicative (no mutation, no assignment) Pure LISP, Miranda, Pure SML *** Declarative (nonprocedural) -system uses general (brute force) techniques (e.g., search) or application dependent techniques (4GLs) -usually only one data structure (program terms) -can use program in different ways (test, find x, gen list) **** Logic-oriented (horn-clauses) Prolog, lambdaProlog, ... program is a set of relations describing the result -computation based on loosely on logic, uses unification, backtracking, search **** Database systems (relations + queries) SQL program is database of relations -computation based on specialized techniques **** Constraint-based TK!Solver, Thinglab, Bertrand (Leler), CLP(R), Prolog III program is set of constraints -constraint is a desired relationship among objects -language does not say how to solve the constraints ------------------------------------------ CONSTRAINT EXAMPLE ; Farenheit and Celsius F = M*C + B ; linear relationship 212 = M*100 + B ; boiling points 32 = M*0 + B ; freezing points F = 80 => C = 26.667 ------------------------------------------ -computation based on constraint-satisfaction techniques e.g., relaxation (for numerical constraints) augmented term rewriting **** Equational-logic based OBJ(3), O'Donnell's "ei" program is set of equations (thought of as rewrite rules) -no logical varaibles computation based on term rewriting (equational logic) often with some additions **** Rule-based (forward chaining) OPS5 program is set of if-then rules -computation based on Rete algorithm reverse(L1,L2) {<[1,2,3], [3,2,1]>, ...}