Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,

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.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Parameter Passing. Variables: lvalues and rvalues In the assignment statement “X=Y”, variables X and Y are being used in different ways. Y is being used.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
© Peter Andreae What is Programming About COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at:
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
Overview of Programming Paradigms
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.
Compiler Design Lexical Analysis Syntactical Analysis Semantic Analysis Optimization Code Generation.
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Introduction (Chapter 1)
Comp 205: Comparative Programming Languages Functional Programming Languages: More Lists Recursive definitions List comprehensions Lecture notes, exercises,
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
Chapter 8 High-Level Programming Languages. 2 Compilers High-level language A language that provides a richer (more English like) set of instructions.
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
 Lesson 03: Computer Programming. The Algorithm A List of Well-Defined Instructions for Completing a Task.
Introduction Computer science is the discipline that seeks to build a scientific foundation for a variety of topics. Computer science provides the underpinnings.
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 © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Programming Languages Meeting 14 December 9/10, 2014.
CS 345: Programming Language Paradigms Chris Brooks HR 510 MWF 11:00-12:05.
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
int k = Integer.MAX_VALUE; k++; int k = Integer.MAX_VALUE; k++; What happens when the following code executes? byte b = someFile.readByte(); b = (byte)(b.
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.
Programming Language Design Issues Programming Languages – Principles and Practice by Kenneth C Louden.
CS 603: Programming Language Organization Lecture 1 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
A Short History of PL's (MacLennan 1999) “Zeroth Generation” (1940's-50's): machine language / assembly: if/then, read/write, store, goto
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
CS314 – Section 5 Recitation 10
Introduction to programming languages, Algorithms & flowcharts
Introduction to programming languages, Algorithms & flowcharts
Principles of programming languages 4: Parameter passing, Scope rules
Comp 205: Comparative Programming Languages
Programming Language History and Evolution
Introduction to programming languages, Algorithms & flowcharts
Representation, Syntax, Paradigms, Types
High Level Programming Languages
Overview of Programming Paradigms
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes, exercises, etc., can be found at:

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 parameterFunction 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) where (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