CS 342 Lecture -*- Outline -*- * Introduction ** Goals of Functional programming *** operate on entire data structures at once (so program at higher level of abstraction) e.g., map, reduce *** equational reasoning allow programs to be manipulated, proved correct, and be derived by substituting equals for equals. ** Techniques *** abstract computations by function arguments *** use functions as data representations allows treatment of infinite data structures (e.g. inf. sets) *** explicitly represent state (so can have equational reasoning) no aliasing! referential transparency (expression always denotes same value) for all f, x: (f x) = (f x) ** Semantic characteristics of Applicative languages *** Binding used instead of assignment Language with assignment: variables denote cells which contain data *draw picture* Language without assignment: identifiers denote values So language without assignment is simplier, because programmers do not have to think in terms of locations (value-oriented) *** Immutable data used instead of mutable data mutable lists: lists are chains of cons cells result of (cons x L) is new cons cell, containing pointers to x and L (sets up an alias to x and L). possibility of circular structures (pointing list to itself) necessity of copying list structures to avoid unwanted sharing. immutable of lists: lists are sequences of elements aliasing of lists cannot be observed (sharing without complications) no need for copying to avoid sharing no circular structures