Functional Programming

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Functional Programming"

Transcription

1 FP Functional Programming WOLFRAM KAHL Department of Computing and Software McMaster University

2 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

3 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

4 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

5 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

6 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

7 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

8 FP What Kinds of Programming Languages are There? Imperative telling the machine what to do Declarative telling the machine what to achieve Programming Languages Imperative Declarative C, Pascal FORTRAN COBOL Modula-2 Object-oriented C++, Oberon-2 Java, Smalltalk Functional Haskell, OCaml ML, Scheme, LISP Logic Prolog Mercury

9 FP Programming Language Paradigms Imperative Programming Languages Statement oriented languages Every statement changes the machine state Object-oriented languages Organising the state into objects with individual state and behaviour Message passing paradigm (instead of subprogram call) Rule-Based (Logical) Programming Languages Specify rule that specifies problem solution (Prolog, BNF Parsing) Other examples: Decision procedures, Grammar rules (BNF) Programming consists of specifying the attributes of the answer Functional (Applicative) Programming Languages Goal is to understand the function that produces the answer Function composition is major operation Programming consists of building the function that computes the answer

10 FP Historical Development of Programming Languages

11 FP Historical Development of Programming Languages Emphasis has changed:

12 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer

13 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer.

14 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer. Easier for the programmer means:

15 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer. Easier for the programmer means: Use languages that facilitate writing error-free programs

16 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer. Easier for the programmer means: Use languages that facilitate writing error-free programs Use languages that facilitate writing programs that are easy to maintain

17 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer. Easier for the programmer means: Use languages that facilitate writing error-free programs Use languages that facilitate writing programs that are easy to maintain Goal of language development:

18 FP Historical Development of Programming Languages Emphasis has changed: from making life easier for the computer to making it easier for the programmer. Easier for the programmer means: Use languages that facilitate writing error-free programs Use languages that facilitate writing programs that are easy to maintain Goal of language development: Developers concentrate on design (or even just specification) Programming is trivial or handled by computer (executable specification languages, rapid prototyping)

19 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

20 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

21 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

22 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

23 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

24 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

25 FP Important Functional Programming Languages Functional Programming Languages pure, statically typed impure Haskell Clean statically typed dynamically typed Standard ML OCaml LISP, Scheme APL, J Erlang

26 FP Haskell

27 FP Haskell functional

28 FP Haskell functional programs are function definitions

29 FP Haskell functional programs are function definitions; functions are first-class citizens

30 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent)

31 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects

32 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy)

33 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed

34 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed

35 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed all type errors caught at compile-time

36 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed all type errors caught at compile-time type classes safe overloading

37 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed all type errors caught at compile-time type classes safe overloading Standardised language version: Haskell 98

38 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed all type errors caught at compile-time type classes safe overloading Standardised language version: Haskell 98 Several compilers and interpreters available

39 FP Haskell functional programs are function definitions; functions are first-class citizens pure (referentially transparent) no side-effects non-strict (lazy) arguments are evaluated only when needed statically strongly typed all type errors caught at compile-time type classes safe overloading Standardised language version: Haskell 98 Several compilers and interpreters available Comprehensive web site:

40 FP Important Points

41 FP Important Points Execution of Haskell programs

42 FP Important Points Execution of Haskell programs is expression evaluation

43 FP Important Points Execution of Haskell programs is expression evaluation (for the time being)

44 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell

45 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics

46 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java

47 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java One Haskell function may be defined by several equations

48 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java One Haskell function may be defined by several equations the first that matches is used

49 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java One Haskell function may be defined by several equations the first that matches is used Lists are an easy-to-use datastructure with lots of language and library support

50 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java One Haskell function may be defined by several equations the first that matches is used Lists are an easy-to-use datastructure with lots of language and library support therefore, lists are heavily used in beginners material.

51 FP Important Points Execution of Haskell programs is expression evaluation (for the time being) Defining functions in Haskell is more like defining functions in mathematics than like defining procedures in C or classes and methods in Java One Haskell function may be defined by several equations the first that matches is used Lists are an easy-to-use datastructure with lots of language and library support therefore, lists are heavily used in beginners material. In many cases, advanced Haskell programmers will use other datastructures, for example Sets, or FiniteMaps instead of association lists.

52 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 = (addition) 4*11-2 (multiplication)

53 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 [subtraction & mult. impossible] = (addition) 4*11-2 (multiplication)

54 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 [subtraction & mult. impossible] = (addition) 4*11-2 (multiplication)

55 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 [subtraction & mult. impossible] = (addition) 4*11-2 [subtraction impossible] (multiplication)

56 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 [subtraction & mult. impossible] = (addition) 4*11-2 [subtraction impossible] = (multiplication) 44-2

57 FP Simple Expression Evaluation The Haskell interpreters hugs, ghci, and hi accept any expression at their prompt and print (after the first ENTER) the value resulting from evaluation of that expression. Prelude> 4*(5+6)-2 42 Expression evaluation proceeds by applying rules to subexpressions: 4*(5+6)-2 [subtraction & mult. impossible] = (addition) 4*11-2 [subtraction impossible] = (multiplication) 44-2 = (subtraction) 42

58 FP Simple Expression Evaluation Explanation

59 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed.

60 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments,

61 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed

62 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument

63 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument

64 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f.

65 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined.

66 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff Constant functions are non-strict: f undefined = undefined.

67 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5

68 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict:

69 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict: null undefined = undefined

70 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict: null undefined = undefined List construction is non-strict:

71 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict: null undefined = undefined List construction is non-strict: null ( undefined : undefined ) = False

72 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict: null undefined = undefined List construction is non-strict: null ( undefined : undefined ) = False Standard arithmetic operators are strict in both arguments:

73 FP Simple Expression Evaluation Explanation Arguments to a fuction or operation are evaluated only when needed. If for obtaining a result from an application of a function f to a number of arguments, the value of the argument at position i is always needed. then f is called strict in its i-th argument Therefore: If f is strict in its i-th argument, then the i-th argument has to be evaluated whenever a result is needed from f. Simpler: A one-argument function f is strict iff f undefined = undefined. Constant functions are non-strict: ( const 5) undefined = 5 Checking a list for emptyness is strict: null undefined = undefined List construction is non-strict: null ( undefined : undefined ) = False Standard arithmetic operators are strict in both arguments: 0 undefined = undefined

74 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) 11111

75 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23)

76 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer)

77 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer) = 41 * (magic * 42-23) (subtraction)

78 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer) = 41 * (magic * 42-23) (subtraction) = 41 * (7 * 42-23) (magic)

79 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer) = 41 * (magic * 42-23) (subtraction) = 41 * (7 * 42-23) (magic) = 41 * (294-23) (multiplication)

80 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer) = 41 * (magic * 42-23) (subtraction) = 41 * (7 * 42-23) (magic) = 41 * (294-23) (multiplication) = 41 * 271 (subtraction)

81 FP Unfolding Definitions Assume the following definitions to be in scope: answer = 42 magic = 7 Expression evaluation will unfold (or expand) definitions: Prelude> (answer - 1) * (magic * answer - 23) (answer - 1) * (magic * answer - 23) = (42-1) * (magic * 42-23) (answer) = 41 * (magic * 42-23) (subtraction) = 41 * (7 * 42-23) (magic) = 41 * (294-23) (multiplication) = 41 * 271 (subtraction) = (multiplication)

82 FP Easy! How did I find those numbers? Prelude> [ n n <- [ ], mod n == 0 ] [1,41,271] This is a list comprehension: return all n where n is taken from then list [ ] and a result is returned only if n divides

83 FP Conditional Expressions Prelude> if mod 41 == 0 then div 41 else The pattern is: if condition then expression1 else expression2 If the condition evaluates to True, the conditional expression evaluates to the value of expression1. If the condition evaluates to False, the conditional expression evaluates to the value of expression2.

84 FP Conditional Expressions Prelude> if mod 41 == 0 then div 41 else The pattern is: if condition then expression1 else expression2 If the condition evaluates to True, the conditional expression evaluates to the value of expression1. If the condition evaluates to False, the conditional expression evaluates to the value of expression2. Therefore: if _ then _ else is strict in the condition.

85 FP Conditional Expressions Prelude> if mod 41 == 0 then div 41 else The pattern is: if condition then expression1 else expression2 If the condition evaluates to True, the conditional expression evaluates to the value of expression1. If the condition evaluates to False, the conditional expression evaluates to the value of expression2. Therefore: if _ then _ else is strict in the condition. In C: ( condition? expression1 : expression2 )

86 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1)

87 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3

88 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1)

89 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1)

90 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1)

91 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1)

92 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1)

93 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1)

94 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1)

95 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1)

96 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1)

97 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1)

98 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1)

99 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1)

100 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1)

101 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1) = 3 * 2 * 1 * if True then 1 else 0 * fact (0-1)

102 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1) = 3 * 2 * 1 * if True then 1 else 0 * fact (0-1) = 3 * 2 * 1 * 1

103 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1) = 3 * 2 * 1 * if True then 1 else 0 * fact (0-1) = 3 * 2 * 1 * 1 = 3 * 2 * 1

104 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1) = 3 * 2 * 1 * if True then 1 else 0 * fact (0-1) = 3 * 2 * 1 * 1 = 3 * 2 * 1 = 3 * 2

105 FP Expanding Function Definitions fact :: Integer -> Integer fact n = if n == 0 then 1 else n * fact (n-1) fact 3 = if 3 == 0 then 1 else 3 * fact (3-1) = if False then 1 else 3 * fact (3-1) = 3 * fact (3-1) = 3 * if (3-1) == 0 then 1 else (3-1) * fact ((3-1)-1) = 3 * if 2 == 0 then 1 else 2 * fact (2-1) = 3 * if False then 1 else 2 * fact (2-1) = 3 * 2 * fact (2-1) = 3 * 2 * if (2-1) == 0 then 1 else (2-1) * fact ((2-1)-1) = 3 * 2 * if 1 == 0 then 1 else 1 * fact (1-1) = 3 * 2 * if False then 1 else 1 * fact (1-1) = 3 * 2 * 1 * fact (1-1) = 3 * 2 * 1 * if (1-1) == 0 then 1 else (1-1) * fact ((1-1)-1) = 3 * 2 * 1 * if 0 == 0 then 1 else 0 * fact (0-1) = 3 * 2 * 1 * if True then 1 else 0 * fact (0-1) = 3 * 2 * 1 * 1 = 3 * 2 * 1 = 3 * 2 = 6

106 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions

107 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * (2 * (1 * fact (1-1)))

108 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * (2 * (1 * fact (1-1)))

109 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1)))

110 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * (1 * fact (1-1)))

111 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1)))

112 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n)

113 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n) = 3 * (2 * (1 * fact 0)) (determining which fact rule matches)

114 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n) = 3 * (2 * (1 * fact 0)) (determining which fact rule matches) = 3 * (2 * (1 * 1)) (fact 0)

115 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n) = 3 * (2 * (1 * fact 0)) (determining which fact rule matches) = 3 * (2 * (1 * 1)) (fact 0) = 3 * (2 * 1) (multiplication)

116 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n) = 3 * (2 * (1 * fact 0)) (determining which fact rule matches) = 3 * (2 * (1 * 1)) (fact 0) = 3 * (2 * 1) (multiplication) = 3 * 2 (multiplication)

117 FP fact :: Integer -> Integer fact 0 = 1 fact n = n * fact (n-1) Matching Function Definitions fact 3 = 3 * fact (3-1) (fact n) = 3 * fact 2 (determining which fact rule matches) = 3 * (2 * fact (2-1)) (fact n) = 3 * (2 * fact 1) (determining which fact rule matches) = 3 * (2 * (1 * fact (1-1))) (fact n) = 3 * (2 * (1 * fact 0)) (determining which fact rule matches) = 3 * (2 * (1 * 1)) (fact 0) = 3 * (2 * 1) (multiplication) = 3 * 2 (multiplication) = 6 (multiplication)

118 FP Lists List display: between square brackets explicitly listing all elements, separated by commas: [1,4,9,16,25]

119 FP Lists List display: between square brackets explicitly listing all elements, separated by commas: [1,4,9,16,25] Enumeration lists: denoted by ellipsis.. inside square brackets; defined by beginning (and end, if applicable): [1.. 10] = [1,2,3,4,5,6,7,8,9,10] [1,3.. 10] = [1,3,5,7,9] [1,3.. 11] = [1,3,5,7,9,11] [11,9.. 1] = [11,9,7,5,3,1] [11.. 1] = [] [1.. ] = [1,2,3,4,5,6,7,8,9,10, ] -- infinite list [1,3.. ] = [1,3,5,7,9,11, ] -- infinite list

120 FP List Construction

121 FP List Construction Display and enumeration lists are syntactic sugar

122 FP List Construction Display and enumeration lists are syntactic sugar: A list is

123 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty

124 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs

125 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes )

126 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes.

127 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor:

128 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : []

129 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3]

130 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3]

131 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3]

132 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3]

133 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3]

134 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right

135 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right: x : y : ys = x : ( y : ys )

136 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right: Example: 1 : 2 : [3,4] x : y : ys = x : ( y : ys )

137 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right: Example: 1 : 2 : [3,4] = 1 : (2 : [3, 4]) x : y : ys = x : ( y : ys )

138 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right: Example: x : y : ys = x : ( y : ys ) 1 : 2 : [3,4] = 1 : (2 : [3, 4]) = 1 : [2, 3, 4]

139 FP List Construction Display and enumeration lists are syntactic sugar: A list is either the empty list: [], or non-empty, and constructed from a head x and a tail xs (read: xes ) x : xs read: x cons xes. : is used as infix list constructor: 3 : [] = [3] 2 : [3] = [2, 3] 1 : [2, 3] = [1, 2, 3] As an infix operator, : associates to the right: Example: x : y : ys = x : ( y : ys ) 1 : 2 : [3,4] = 1 : (2 : [3, 4]) = 1 : [2, 3, 4] = [1, 2, 3, 4]

140 FP Cons is Not Associative

141 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances.

142 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative:

143 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4])

144 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4]

145 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4]

146 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4]

147 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense

148 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list!

149 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]]

150 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]] = [[2],[3,4,5],[6,7]]

151 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]] = [[2],[3,4,5],[6,7]] Another list of lists of integers: (1 : [2]) : [[3,4,5], [6,7]]

152 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]] = [[2],[3,4,5],[6,7]] Another list of lists of integers: (1 : [2]) : [[3,4,5], [6,7]] = [[1,2],[3,4,5],[6,7]]

153 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]] = [[2],[3,4,5],[6,7]] Another list of lists of integers: (1 : [2]) : [[3,4,5], [6,7]] = [[1,2],[3,4,5],[6,7]] 1 : ([2] : [[3,4,5], [6,7]])

154 FP Cons is Not Associative The convention that : associates to the right allows to save parentheses in certain cirtcumstances. However, : is not associative: A list of integers: 1 : (2 : [3,4]) = 1 : 2 : [3,4] = [1, 2, 3, 4] (1 : 2) : [3,4] is nonsense, since 2 is not a list! A list of lists of integers: [2] : [[3,4,5], [6,7]] = [[2],[3,4,5],[6,7]] Another list of lists of integers: (1 : [2]) : [[3,4,5], [6,7]] = [[1,2],[3,4,5],[6,7]] 1 : ([2] : [[3,4,5], [6,7]]) is nonsense again!

Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,

More information

What is OOP (and why does it matter?)

What is OOP (and why does it matter?) What is OOP (and why does it matter?) CAS London 2016 Michael Kölling University of Kent 1957 1960 1965 1970 1975 1980 1985 1990 ALGOL 58 ALGOL 60 SIMULA I SIMULA 67 PASCAL MODULA 2 OBERON MODULA 3 ADA

More information

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming. Functional Programming Languages. Chapter 14. Introduction Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages Course Organization Introduction CSE 307: Principles of Programming Languages Spring 2015 R. Sekar Course Organization Introduction 1 / 34 Topics 1. Course Organization Info and Support Course Description

More information

CSCI 3136 Principles of Programming Languages

CSCI 3136 Principles of Programming Languages CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University

More information

Lecture 1: Introduction

Lecture 1: Introduction Programming Languages Lecture 1: Introduction Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Lecture 1 Introduction 2 Lecture Outline Preview History of Programming

More information

Review questions for Chapter 9

Review questions for Chapter 9 Answer first, then check at the end. Review questions for Chapter 9 True/False 1. A compiler translates a high-level language program into the corresponding program in machine code. 2. An interpreter is

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

1.1 WHAT IS A PROGRAMMING LANGUAGE?

1.1 WHAT IS A PROGRAMMING LANGUAGE? 1 INTRODUCTION 1.1 What is a Programming Language? 1.2 Abstractions in Programming Languages 1.3 Computational Paradigms 1.4 Language Definition 1.5 Language Translation 1.6 Language Design How we communicate

More information

The countdown problem

The countdown problem JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON

More information

CSC 272 - Software II: Principles of Programming Languages

CSC 272 - Software II: Principles of Programming Languages CSC 272 - Software II: Principles of Programming Languages Lecture 1 - An Introduction What is a Programming Language? A programming language is a notational system for describing computation in machine-readable

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk

History OOP languages Year Language 1967 Simula-67 1983 Smalltalk History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming

More information

Functional Programming in C++11

Functional Programming in C++11 Functional Programming in C++11 science + computing ag IT-Dienstleistungen und Software für anspruchsvolle Rechnernetze Tübingen München Berlin Düsseldorf An Overview Programming in a functional style

More information

Chapter 1. Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705. CS-4337 Organization of Programming Languages

Chapter 1. Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705. CS-4337 Organization of Programming Languages Chapter 1 CS-4337 Organization of Programming Languages Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705 Chapter 1 Topics Reasons for Studying Concepts of Programming

More information

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code 1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons

More information

Assembly Languages. Topic 4. Programming Languages. Assembly Languages. High-level Languages. Abstracting further from the Nuts and Bolts

Assembly Languages. Topic 4. Programming Languages. Assembly Languages. High-level Languages. Abstracting further from the Nuts and Bolts Topic 4 Assembly Languages Programming Languages Abstracting further from the Nuts and Bolts CPU (the core of the computer) responds to binary instructions only. The very first computer programs were written

More information

05 Case Study: C Programming Language

05 Case Study: C Programming Language CS 2SC3 and SE 2S03 Fall 2009 05 Case Study: C Programming Language William M. Farmer Department of Computing and Software McMaster University 18 November 2009 The C Programming Language Developed by Dennis

More information

Concepts of Programming Languages: A Unified Approach. Karl Abrahamson

Concepts of Programming Languages: A Unified Approach. Karl Abrahamson Concepts of Programming Languages: A Unified Approach Karl Abrahamson August 2013 2 Copyright (c) 2013 Karl Abrahamson. Contents 1 Introduction to Programming Languages 11 1.1 Programming languages.............................

More information

The current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons

The current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values

More information

Programming Languages

Programming Languages Programming Languages Qing Yi Course web site: www.cs.utsa.edu/~qingyi/cs3723 cs3723 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer Science Office:

More information

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent. Course Goal CMSC 330: Organization of Programming Languages Introduction Instructors: Michael Hicks and Anwar Mamat Learn how programming languages work Broaden your language horizons Different programming

More information

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages Announcements Programming Languages! Monday evening GBA section has been shut down " If you were assigned to this section, please find a different section " If you cannot attend a different section, please

More information

Chapter 1. 1.1Reasons for Studying Concepts of Programming Languages

Chapter 1. 1.1Reasons for Studying Concepts of Programming Languages Chapter 1 1.1Reasons for Studying Concepts of Programming Languages a) Increased ability to express ideas. It is widely believed that the depth at which we think is influenced by the expressive power of

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Introduction Instructors: Mike Hicks, Dave Levin 1 Course Goal Learn how programming languages work! Broaden your language horizons Different programming

More information

Programming Languages in Artificial Intelligence

Programming Languages in Artificial Intelligence Programming Languages in Artificial Intelligence Günter Neumann, German Research Center for Artificial Intelligence (LT Lab, DFKI) I. AI programming languages II. Functional programming III. Functional

More information

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg Principles of Programming Languages Topic: Introduction Professor Louis Steinberg CS 314, LS,LTM: L1: Introduction 1 Contacts Prof. Louis Steinberg lou @ cs.rutgers.edu x5-3581 401 Hill TA: to be announced

More information

Object-Oriented Programming. Lecture 1 Dr Piotr Cybula

Object-Oriented Programming. Lecture 1 Dr Piotr Cybula Object-Oriented Programming Lecture 1 Dr Piotr Cybula Literature Bruce Eckel: Thinking in C++. Second edition. Vol. 1. (http://mindview.net/books/ticpp/thinkingincpp2e.html) Robert

More information

Programming Languages and Compilers

Programming Languages and Compilers Programming Languages and Compilers Qing Yi class web site: www.cs.utsa.edu/~qingyi/cs5363 cs5363 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer

More information

CSE 130 Programming Language Principles & Paradigms

CSE 130 Programming Language Principles & Paradigms CSE 130 Programming Language Principles & Paradigms Thomas A. Powell tpowell@pint.com Housekeeping Syllabus review Direct class page link http://www.pint.com/classes/cse130 Updated syllabus, notes, homework

More information

Ordering Program Execution: What is Done First? Control Flow. Expression Evaluation. Expression Evaluation Ordering: Precedence and Associativity

Ordering Program Execution: What is Done First? Control Flow. Expression Evaluation. Expression Evaluation Ordering: Precedence and Associativity Control Flow In this set of notes you will learn about: Expression evaluation order Assignments Structured and unstructured flow Goto s Sequencing Selection Iteration Recursion Copyright R.A. van Engelen,

More information

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz 2007 03 16

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz 2007 03 16 Advanced compiler construction Michel Schinz 2007 03 16 General course information Teacher & assistant Course goals Teacher: Michel Schinz Michel.Schinz@epfl.ch Assistant: Iulian Dragos INR 321, 368 64

More information

Chapter 6: Programming Languages

Chapter 6: Programming Languages Chapter 6: Programming Languages Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 6: Programming Languages 6.1 Historical Perspective

More information

Semester Review. CSC 301, Fall 2015

Semester Review. CSC 301, Fall 2015 Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!

More information

+ addition - subtraction and unary minus * multiplication / division mod modulo

+ addition - subtraction and unary minus * multiplication / division mod modulo Chapter 4 Basic types We examine in this chapter the Caml basic types. 4.1 Numbers Caml Light provides two numeric types: integers (type int) and floating-point numbers (type float). Integers are limited

More information

7.1 Our Current Model

7.1 Our Current Model Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.

More information

CONCEPTS IN PROGRAMMING LANGUAGES. John C. Mitchell Stanford University

CONCEPTS IN PROGRAMMING LANGUAGES. John C. Mitchell Stanford University CONCEPTS IN PROGRAMMING LANGUAGES John C. Mitchell Stanford University published by the press syndicate of the university of cambridge The Pitt Building, Trumpington Street, Cambridge, United Kingdom cambridge

More information

Integrating Formal Models into the Programming Languages Course

Integrating Formal Models into the Programming Languages Course Integrating Formal Models into the Programming Languages Course Allen B. Tucker Robert E. Noonan Computer Science Department Computer Science Department Bowdoin College College of William and Mary Brunswick,

More information

Organization of Programming Languages CS3200 / 5200N. Lecture 07

Organization of Programming Languages CS3200 / 5200N. Lecture 07 Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Control Flow Control flow = the flow of control, or execution

More information

1998. (R. Bird and P. Wadler, Introduction to Functional Programming, Prentice

1998. (R. Bird and P. Wadler, Introduction to Functional Programming, Prentice Mathematical Structures in Programs 15 Algebra) The Shorter Oxford English Dictionary): the reunion of broken parts a calculus of symbols combined according to defined laws Haskell 3 4 Richard Bird. Introduction

More information

Intro to Programming: Basic Definitions

Intro to Programming: Basic Definitions Intro to Programming: Basic Definitions Programming: The planning, scheduling, or performing of a task or event Computer program: A sequence of instructions for a computer to execute Computer: An electronic,

More information

Concepts of Programming Languages. Robert W. Sebesta

Concepts of Programming Languages. Robert W. Sebesta Concepts of Programming Languages Robert W. Sebesta Chapter 1 Preliminaries Reasons for studying the underlying concepts of programming languages The Study of Programming Languages Increases our ability

More information

Introduction to Software Paradigms & Procedural Programming Paradigm

Introduction to Software Paradigms & Procedural Programming Paradigm Introduction & Procedural Programming Sample Courseware Introduction to Software Paradigms & Procedural Programming Paradigm This Lesson introduces main terminology to be used in the whole course. Thus,

More information

Programming Language Syntax

Programming Language Syntax Programming Language Syntax Natural language vs. programming language No ambiguity allowed in programming languages in form (syntax) and meaning (semantics) Thus, programming language specifications use

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

The Clean programming language. Group 25, Jingui Li, Daren Tuzi The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was

More information

2. Names, Scopes, and Bindings

2. Names, Scopes, and Bindings 2. Names, Scopes, and Bindings Binding, Lifetime, Static Scope, Encapsulation and Modules, Dynamic Scope Copyright 2010 by John S. Mallozzi Names Variables Bindings Binding time Language design issues

More information

Subroutines and Control Abstraction

Subroutines and Control Abstraction Subroutines and Control Abstraction CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2012 Reading: Chapter 8 Abstractions as Program Building Blocks

More information

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014! Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)

More information

Programming Fundamentals 2

Programming Fundamentals 2 Programming Fundamentals 2 This chapter begins the examination of what programming is and how a programming language like Java works. In particular, it introduces the basic ideas and concepts of imperative

More information

McGraw-Hill The McGraw-Hill Companies, Inc., 20 1. 01 0

McGraw-Hill The McGraw-Hill Companies, Inc., 20 1. 01 0 1.1 McGraw-Hill The McGraw-Hill Companies, Inc., 2000 Objectives: To describe the evolution of programming languages from machine language to high-level languages. To understand how a program in a high-level

More information

by Mario Fusco mario.fusco@gmail.com twitter: @mariofusco Monadic

by Mario Fusco mario.fusco@gmail.com twitter: @mariofusco Monadic by Mario Fusco mario.fusco@gmail.com twitter: @mariofusco Monadic Imperative languages Java C# C / C++ Fortran Add abstractions Scala F# Subtract abstractions Hybrid languages Algol Lisp ML Haskell Functional

More information

Q1. For the following grammar: S a S b c E E d f E a

Q1. For the following grammar: S a S b c E E d f E a Chapter 3 (3.1 3.3) Describing Syntax and Semantics Chapter 4 Lexical and Syntax Analysis Chapter 5 Names, Binding, Type Checking and Scopes Chapter 6 Data Types Chapter 7 Expressions and Assignment Statements

More information

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages ICOM 4036 Programming Languages Preliminaries Dr. Amirhossein Chinaei Dept. of Electrical & Computer Engineering UPRM Spring 2010 Language Evaluation Criteria Readability: the ease with which programs

More information

Chapter 13 Computer Programs and Programming Languages. Discovering Computers 2012. Your Interactive Guide to the Digital World

Chapter 13 Computer Programs and Programming Languages. Discovering Computers 2012. Your Interactive Guide to the Digital World Chapter 13 Computer Programs and Programming Languages Discovering Computers 2012 Your Interactive Guide to the Digital World Objectives Overview Differentiate between machine and assembly languages Identify

More information

Data Abstraction and Object Orientation. CSE 307 Principles of Programming Languages Stony Brook University

Data Abstraction and Object Orientation. CSE 307 Principles of Programming Languages Stony Brook University Data Abstraction and Object Orientation CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Object-Oriented Programming Control or PROCESS abstraction

More information

1 Operational Semantics for While

1 Operational Semantics for While Models of Computation, 2010 1 1 Operational Semantics for While The language While of simple while programs has a grammar consisting of three syntactic categories: numeric expressions, which represent

More information

The Anatomy of Programming Languages

The Anatomy of Programming Languages The Anatomy of Programming Languages Alice E. Fischer University of New Haven Frances S. Grodzinsky Sacred Heart University September 1992 ii Copyright c 1990, 1991, 1992 by Alice E. Fischer and Frances

More information

How to simplify software development with high level programming languages? Pierre-Alexandre Voye - ontologiae@gmail.com

How to simplify software development with high level programming languages? Pierre-Alexandre Voye - ontologiae@gmail.com How to simplify software development with high level programming languages? Pierre-Alexandre Voye - ontologiae@gmail.com Projects structures - Both in proprietary and open source project, steps are the

More information

On the (un)suitability of Java to be the first programming language

On the (un)suitability of Java to be the first programming language On the (un)suitability of Java to be the first programming language Mirjana Ivanovic Faculty of Science, Department of Mathematics and Informatics Trg Dositeja Obradovica 4, Novi Sad mira @im.ns.ac.yu

More information

1 Enumeration Problem

1 Enumeration Problem Enumerating the Strings of a Regular Expression Jayadev Misra 8/29/2000; revised 9/26/2003; revised 8/15/2011 We develop a program in Haskell to enumerate the strings of a regular expression in increasing

More information

[Refer Slide Time: 05:10]

[Refer Slide Time: 05:10] Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture

More information

Cedalion A Language Oriented Programming Language (Extended Abstract)

Cedalion A Language Oriented Programming Language (Extended Abstract) Cedalion A Language Oriented Programming Language (Extended Abstract) David H. Lorenz Boaz Rosenan The Open University of Israel Abstract Implementations of language oriented programming (LOP) are typically

More information

F U N C T I O N A L P E A R L S Monadic Parsing in Haskell

F U N C T I O N A L P E A R L S Monadic Parsing in Haskell Under consideration for publication in J. Functional Programming 1 F U N C T I O N A L P E A R L S Monadic Parsing in Haskell Graham Hutton University of Nottingham Erik Meijer University of Utrecht 1

More information

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/

More information

1/20/2016 INTRODUCTION

1/20/2016 INTRODUCTION INTRODUCTION 1 Programming languages have common concepts that are seen in all languages This course will discuss and illustrate these common concepts: Syntax Names Types Semantics Memory Management We

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Parameter passing in LISP

Parameter passing in LISP Parameter passing in LISP The actual parameters in a function call are always expressions, represented as lists structures. LISP provides two main methods of parameter passing: Pass/Call-by-value. The

More information

Programming Languages. National Chiao Tung University Chun-Jen Tsai 05/4/2012

Programming Languages. National Chiao Tung University Chun-Jen Tsai 05/4/2012 Programming Languages National Chiao Tung University Chun-Jen Tsai 05/4/2012 Programming Language Programming Language (PL) is a language that can precisely describe an algorithm to a computer so that

More information

Testing and Tracing Lazy Functional Programs using QuickCheck and Hat

Testing and Tracing Lazy Functional Programs using QuickCheck and Hat Testing and Tracing Lazy Functional Programs using QuickCheck and Hat Koen Claessen 1, Colin Runciman 2, Olaf Chitil 2, John Hughes 1, and Malcolm Wallace 2 1 Chalmers University of Technology, Sweden

More information

Special Topics: Programming Languages

Special Topics: Programming Languages Lecture #2 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture #2.5 Lecture #2 1 Slide 1 Recapitulation Computers work in machine language, which is difficult for

More information

EXPRESSIONS AND ASSIGNMENT STATEMENTS. Copyright 2009 Addison-Wesley. All rights reserved. 1-1

EXPRESSIONS AND ASSIGNMENT STATEMENTS. Copyright 2009 Addison-Wesley. All rights reserved. 1-1 EXPRESSIONS AND ASSIGNMENT STATEMENTS Copyright 2009 Addison-Wesley. All rights reserved. 1-1 Introduction Expressions are the fundamental means of specifying computations in a programming language To

More information

Languages september 12, 2015 Éric Lévénez 1999-2015 <http://www.levenez.com/lang/> FORTRAN III end-1958 FORTRAN II 1957. FORTRAN I october 1956

Languages september 12, 2015 Éric Lévénez 1999-2015 <http://www.levenez.com/lang/> FORTRAN III end-1958 FORTRAN II 1957. FORTRAN I october 1956 1954 1957 FORTRAN november 1954 FORTRAN I october 1956 FORTRAN II 1957 FORTRAN III end-1958 B-O 1957 Flow-Matic 1958 COBOL 1959 JOVIAL 1959 IAL 1958 ALGOL 58 1958 Lisp 1958 Lisp 1 1959 Languages september

More information

SL-110: Fundamentals of Java Revision 15 October Sun Educational Services Instructor-Led Course Description

SL-110: Fundamentals of Java Revision 15 October Sun Educational Services Instructor-Led Course Description Sun Educational Services Instructor-Led Course Description Fundamentals of Java SL-110 The Fundamentals of the Java course provides students, with little or no programming experience, with the basics of

More information

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT Selvakumar Samuel Asia Pacific University of Technology and Innovation Technology Park Malaysia 57000 Bukit Jalil, Malaysia. Email:

More information

Chapter 6 Finite sets and infinite sets. Copyright 2013, 2005, 2001 Pearson Education, Inc. Section 3.1, Slide 1

Chapter 6 Finite sets and infinite sets. Copyright 2013, 2005, 2001 Pearson Education, Inc. Section 3.1, Slide 1 Chapter 6 Finite sets and infinite sets Copyright 013, 005, 001 Pearson Education, Inc. Section 3.1, Slide 1 Section 6. PROPERTIES OF THE NATURE NUMBERS 013 Pearson Education, Inc.1 Slide Recall that denotes

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

programming languages, programming language standards and compiler validation

programming languages, programming language standards and compiler validation Software Quality Issues when choosing a Programming Language C.J.Burgess Department of Computer Science, University of Bristol, Bristol, BS8 1TR, England Abstract For high quality software, an important

More information

Anatomy of Programming Languages. William R. Cook

Anatomy of Programming Languages. William R. Cook Anatomy of Programming Languages William R. Cook Copyright (C) 2013 2 Chapter 1 Preliminaries Preface What? This document is a series of notes about programming languages, originally written for students

More information

CSE 130 Programming Language Principles & Paradigms

CSE 130 Programming Language Principles & Paradigms CSE 130 Programming Language Principles & Paradigms Thomas A. Powell tpowell@pint.com Housekeeping Syllabus review Direct class page link http://www.pint.com/classes/cse130 Updated syllabus, notes, homework

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

SIT102 Introduction to Programming

SIT102 Introduction to Programming SIT102 Introduction to Programming After working through this session you should: Understand the relationships between operating systems, their user interfaces, and programs; Understand the difference

More information

Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm

Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm Table of Contents 1 Introduction... 2 1.1 Programming Paradigm... 2 1.2 Software Design Paradigm... 3 1.2.1 Design Patterns...

More information

CSC 7101: Programming Language Structures 1

CSC 7101: Programming Language Structures 1 Types in Programming Languages Stansifer Ch. 4 Cardelli Sec. 1 1 Types Organization of untyped values Untyped universes: bit strings, S-expr, Categorize based on usage and behavior Type = set of computational

More information

Helmut Seidl. Virtual Machines. München. Summer 2011

Helmut Seidl. Virtual Machines. München. Summer 2011 Helmut Seidl Virtual Machines München Summer 2011 1 0 Introduction Principle of Interpretation: Program + Input Interpreter Output Advantage: No precomputation on the program text startup-time == no/short

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 18: Intermediate Code 29 Feb 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 18: Intermediate Code 29 Feb 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 18: Intermediate Code 29 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Summary: Semantic Analysis Check errors not detected by lexical

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation Lecture Outline Programming Languages CSCI-4430 & CSCI-6430, Spring 2016 www.cs.rpi.edu/~milanova/csci4430/ Ana Milanova Lally Hall 314, 518 276-6887 milanova@cs.rpi.edu Office hours: Wednesdays Noon-2pm

More information

Introduction. Learning Outcomes and Content. Computing Facilities

Introduction. Learning Outcomes and Content. Computing Facilities COMP348/2 Fall 2016 Section U Principles of Programming Languages (3 credits) Course Outline / Syllabus Prerequisites: COMP248 or COMP249 or COMP238 From September 6 th to December 5 th 2015 Section Instructors

More information

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1 CS 1621 MIDTERM EXAM 1 Name: Problem 1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Score Page 1 1. (1 x 17 = 17 points) Determine if each of the following statements

More information

Object-Oriented Software Specification in Programming Language Design and Implementation

Object-Oriented Software Specification in Programming Language Design and Implementation Object-Oriented Software Specification in Programming Language Design and Implementation Barrett R. Bryant and Viswanathan Vaidyanathan Department of Computer and Information Sciences University of Alabama

More information

COMP 356 Programming Language Structures Notes for Chapter 5 of Concepts of Programming Languages Names, Types and Scopes

COMP 356 Programming Language Structures Notes for Chapter 5 of Concepts of Programming Languages Names, Types and Scopes Some definitions: COMP 356 Programming Language Structures Notes for Chapter 5 of Concepts of Programming Languages Names, Types and Scopes a name is a string of characters (a word) that represents a program

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement

More information

5 Procedural Abstraction

5 Procedural Abstraction 5 Procedural Abstraction Proper procedures and function procedures. Parameters and arguments. Implementation notes. 2004, D.A. Watt, University of Glasgow 1 1 Abstraction In programming, abstraction means

More information

Group number 24 Joni Saarinen Daniel Kullberg

Group number 24 Joni Saarinen Daniel Kullberg C# Group number 24 Joni Saarinen Daniel Kullberg C# (pronounced C sharp) is a multi paradigm programming language developed by Microsoft. It is primarily an imperative language but support for functional

More information

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction ATSBA: Advanced Technologies Supporting Business Areas Programming with Java 1 Overview and Introduction 1 1 Overview and Introduction 1 Overview and Introduction 1.1 Programming and Programming Languages

More information