Comp 205: Comparative Programming Languages

Slides:



Advertisements
Similar presentations
06/01/101 Functional Programming GC16 / 3011 Chris Clack.
Advertisements

Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at:
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Unit 181 Recursion Definition Recursive Methods Example 1 How does Recursion work? Example 2 Problems with Recursion Infinite Recursion Exercises.
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
High-Level Programming Languages
CS 101 Course Summary December 5, Big Ideas Abstraction Problem solving Fundamentals of programming.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
Comp 205: Comparative Programming Languages Functional Programming Languages: More Lists Recursive definitions List comprehensions Lecture notes, exercises,
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
Chapter 1 - Introduction
1 Programming Language History and Evolution In Text: Chapter 2.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 6: Recursion Lecturer: Santokh Singh Assignment 1 due tomorrow. Should have started working.
Programming Languages
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Programming Languages
CPS120: Introduction to Computer Science Variables and Constants.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
CS 603: Programming Language Organization Lecture 1 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
Dr. Philip Cannata 1 Functions and Recursion Programming Languages.
Programming Language Paradigms ITSK2314 Lecture 3.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
CPS120 Introduction to Computer Science High Level Language: Paradigms.
CS314 – Section 5 Recitation 9
Programming Language History and Evolution
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Programming Languages 2nd edition Tucker and Noonan
CS314 – Section 5 Recitation 10
The language focusses on ease of use
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
Concepts of Programming Languages
Introduction to programming languages, Algorithms & flowcharts
Introduction to programming languages, Algorithms & flowcharts
Programming Language Design Concepts
Parameter passing Module 12.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Representation, Syntax, Paradigms, Types
Principles of programming languages 4: Parameter passing, Scope rules
Programming Language History and Evolution
Introduction to programming languages, Algorithms & flowcharts
Chap. 6 :: Control Flow Michael L. Scott.
Programming Language Design
Elements of Programming Languages
Functional Programming
Representation, Syntax, Paradigms, Types
Chap. 6 :: Control Flow Michael L. Scott.
Programming Languages 2nd edition Tucker and Noonan
High Level Programming Languages
Representation, Syntax, Paradigms, Types
Chapter 6: Programming Languages
Principles of Programming Languages
Overview of Programming Paradigms
Type Systems Terms to learn: Type Type system
Representation, Syntax, Paradigms, Types
Programming Languages and Paradigms
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Type Systems Terms to learn about types: Related concepts: Type
Functional Programming and Haskell
Functional Programming and Haskell
Presentation transcript:

Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes, exercises, etc., can be found at: www.csc.liv.ac.uk/~grant/Teaching/COMP205/

Functional Languages Today, we will look at: Functions Types Languages (primarily Haskell)

Levels of Abstraction Hardwiring (logic gates) Machine code (chip-set instructions) Assembly language "High-level" languages (Fortran, Algol, Cobol, Pascal, Ada, Modula) Object-oriented languages (Simula67, Smalltalk, Java) Declarative languages … Specification languages (OBJ, Z)

Code Generation Gaps "Select all items in an integer array that are less than 10" j := 1; FOR i := 1 TO LineLength DO IF line[i] < 10 THEN newline[j] := line[i]; j := j + 1; END From Chris Clack et al., Programming with Miranda. Prentice Hall, London 1995.

Declarative Languages Declarative Languages can be divided into Functional and Logic languages. Functional languages include: LISP SML Haskell Hope Logic languages include Prolog Eqlog

What is a Function? y = 2 * x x  2 * x twice(x) = 2 * x twice x = 2 * x (Prefix Notation)

Some Terminology twice x = 2 * x Function name Formal parameter Function body

Formal Parameters Formal parameters can be renamed: twice x = 2 * x twice z = 2 * z twice i = 2 * i

Formal Parameters Again Formal parameters can be renamed: public static int twice(int x) { return 2 * x ; } is the same as: public static int twice(int i) { return 2 * i ; }

Actual Parameters Function evaluation works by substituting an actual parameter for a formal parameter: twice x = 2 * x twice 7 = 2 * 7 = 14

Actual Parameters Again The same kind of evaluation through substitution is at work in imperative languages: public static int twice(int x) { return 2 * x ; } ... int i = twice(7); // i = 14

Programming with Functions Functional programming languages allow direct definitions of what is to be computed (rather than the how of imperative programming languages) twice x = 2 * x

Functions and Types I Functions need not be restricted to numbers; they can work on any sort of data. Among the data structures of interest to Computer Science are: boolean values (true, false) characters strings lists trees graphs

Functions and Types II The type of a function refers to the kind of argument it takes, and the kind of result it returns. The function twice takes a number as argument and returns a number as result; its type is: num  num Or: twice : num  num

Functional Programming Languages The example twice is misleading, because its definition looks algorithmic. Not all functions are as easy to express in a programming language….

The Fibonacci Sequence 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …. Each number in this sequence is the sum of the two preceding numbers (apart from the first two). fib 0 = 1 fib 1 = 1 fib n = (fib (n-2)) + (fib (n-1)), if n > 1

The Fibonacci Sequence (Java remix) public static int fib(int n) { int i = 0; int x = 1; int y = 1; while (i < n) y += x; x = y - x; i++; } return x;

The Fibonacci Sequence (Haskell remix) fib n = fib1 where (fib1, fib2) = fibs n fibs 0 = (1,1) fibs n = (f2, f1 + f2) (f1,f2) = fibs (n-1), if n > 0

Factorials The factorial of a number n is the product of all the numbers from 1 to n : fact n = 1 * 2 * ••• * n However, this can be defined recursively: fact 0 = 1 fact n = (fact (n-1)) * n

Summary Functions work by substitution and evaluation Functions can have types Functional programming languages also work by substitution and evaluation Functional programming languages emphasise what is to be computed, rather than how Next: Haskell