Programming Languages Meeting 9 November 1/2, 2016
Functional Programming Languages Work with pure FP languages No assignment statement No loops No objects or methods Still have sequence implemented as composition Recall [s1;s2] = [s2]○ [s1] Still have if – then – else Loops are replaced by recursion
FP (2) Four components Objects Primitive functions Functional forms Function definition mechanism, for secondary functions
Objects The only data type Not the objects from Java, but: Objects Atoms Lists of objects The symbol called bottom, signifying “undefined”
Atoms Forms of atoms sequence of characters, a string, an identifier sequence of digits, an integer [perhaps with sign] syntax of a real number T, meaning true F, meaning false
Functions Functions on the set of objects, the only operation on objects Programs are constructed using composition of functions. Two types of functions Entire: Defined on all objects Partial: Defined on some, but not all objects
Notation for Semantics One line function specification with choices, developed by John Backus Symbols : apply the function to the argument is defined as −> if – then ; else
Primitives Our set of primitives: first last head tail atom? null? list?
More Primitives appendr appendl length The arithmetic functions The comparison functions
Functional Forms The four Cs constant composition denoted by overbar depends on one object composition denoted by centered small circle depends on two functions
Functional Forms (2) construction conditional denoted by [ ] depends on n functions [f]:x <−> <f:x> (n=1) conditional denoted using −> and ; depends on a predicate and two functions
Functional Forms (3) apply to all insert (also known as reduce) denoted by αf depends on one function works only on lists insert (also known as reduce) denoted by /f depends on one function with a number of properties