© M. Winter COSC 4P41 – Functional Programming 1.11.1 COSC 4P41 Functional Programming Instructor: Michael Winter –Office J323 –Office Hours: Tue & Wed.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Lecture 2 Introduction to C Programming
Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
© M. Winter COSC 4P42 – Formal Methods in Software Engineering COSC 4P42 Formal Methods in Software Engineering Course: –Lecture: Wed & Fri, 11:00am.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
ISBN Chapter 15 Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages Introduction to.
CS1061 C Programming Lecture 5: Building Blocks of Simple Programs A. O’Riordan, 2004.
Data types and variables
ISBN Chapter 15 Functional Programming Languages.
Chapter 2 Data Types, Declarations, and Displays
ISBN Chapter 15 Functional Programming Languages.
Objectives You should be able to describe: Data Types
1 CSCE Programming Languages Introduction and Course Administration Dr. Hyunyoung Lee 410B HR Bright
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
COE Computer Organization & Assembly Language Talal Alkharobi.
Imperative Programming
CH Programming An introduction to programming concepts.
CIS Computer Programming Logic
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
ISBN Chapter 15 Functional Programming Languages.
Haskell. 2 GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
ISBN Chapter 15 Functional Programming Languages.
Input, Output, and Processing
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
© M. Winter COSC 4P41 – Functional Programming COSC 4P41 Functional Programming Instructor: Michael Winter –Office J323 –Office Hours: Wed & Fri.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
ISBN Chapter 15 Functional Programming Languages.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
Administrative Preliminaries Computer Architecture.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
CS314 – Section 5 Recitation 9
INC 161 , CPE 100 Computer Programming
Functional Programming
Functional Programming Languages
COSC 5V90 Functional Programming and Interactive Theorem Proving
Types CSCE 314 Spring 2016.
Information Science and Engineering
Chapter 2 - Introduction to C Programming
Haskell.
Chapter 2 - Introduction to C Programming
COSC 4P41 Functional Programming
Higher-Order Procedures
Functional Programming Languages
CS 425 / CS 625 Software Engineering
Summary of what we learned yesterday
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Chapter 15 Functional Programming 6/1/2019.
Introduction to C Programming
Presentation transcript:

© M. Winter COSC 4P41 – Functional Programming COSC 4P41 Functional Programming Instructor: Michael Winter –Office J323 –Office Hours: Tue & Wed 10:00am - 12:00pm – Webpage: Course Description (Brock Calendar): Introduction to functional programming using the languages Haskell. Topics include all data types, type inference, pattern-matching, recursion, polymorphism, higher-order functions, lazy vs eager evaluation, modules and monads. Prerequisites: None Haskell: course procedures –plagiarism

© M. Winter COSC 4P41 – Functional Programming Textbooks Main Text – Haskell, The Craft of Functional Programming, 2 nd edition, S. Thompson, Addison - Wesley (1999), ISBN Supplemental Texts – The Hugs 98 User Manual, Mark P Jones, Alastair Reid, online documentation. – Real World Haskell, Bryan O'Sullivan, John Goerzen, Don Steward, O'Reilly (2009), ISBN – The Haskell School of Expression, P. Hudak, Cambridge University Press (2000), ISBN

© M. Winter COSC 4P41 – Functional Programming Course Work Marking Scheme –Programming Assignments (2x10%,2x20%)60% –Final Exam (oral) 40% Programming Assignments NumberDueLate 1Sep 1:00pm Sep 1:00pm 2Oct 1:00pm Oct 1:00pm 3Nov 1:00pm Nov 1:00pm 4Nov 1:00pm Dec 1:00pm Registration for final exam: Mid of October (Office hours or after class) Final Exam (oral, 30min each): Monday, December 07, 2009

© M. Winter COSC 4P41 – Functional Programming Assignments will be available online. Submission is electronically. Details see webpage. Assignments will be returned by . Assignments are due at the times specified above and will be accepted late until the indicated time, subject to a penalty of 25%. After the late period, assignments will not be accepted. A mark of at least 40% on the final exam is required to achieve a passing grade in this course. Assignments will be carefully examined regarding plagiarism. Cases of suspected plagiarism will be dealt with according to the University regulations and Departmental procedures. Consideration regarding illness for assignment submission or test dates will only be considered if accompanied with the completed Departmental Medical Excuse form.

© M. Winter COSC 4P41 – Functional Programming Course Outline WeekDateBook/Chapt.Topics 1Sep 14/16[1] 1–3Introduction to Functional Programming 2Sep 21/23[1] 4–5Recursion and Data Types 3Sep 28/30[1] 6–7Lists 4Oct 05/07[1] 9-10Patterns of Computation, Functions as Values 5Oct 14/19*[1] 12-13Overloading, Type Classes, Type Checking 6Oct 21/26[1] 14-15Algebraic Types 7Oct 28/Nov 02[1] 16Abstract Data Types 8Nov 04/09[1] 17Lazy Evaluation 9Nov 11/16[1] 18Programming with Actions 10Nov 18/23[1] 8, 14.7 & 17.9Reasoning about Programs 11Nov 25/30[1] 8, 14.7 & 17.9Reasoning about Programs II 12Dec 02/03[2] 7Hugs – Language extensions, Review * October 12 is Thanksgiving, no classes. Make up on December 03.

© M. Winter COSC 4P41 – Functional Programming Imperative languages Von Neumann model: –store with addressable locations machine code: –effect achieved by changing contents of store locations –instructions executed in sequence, flow of control altered by jumps imperative language: –variable corresponds to store location –instructions executed in sequence, flow of control altered by conditional and loop statements –efficient implementation since close to design of conventional computers

© M. Winter COSC 4P41 – Functional Programming Functional languages computational model: lambda calculus mathematical functions: domain, range functional languages achieve effect by applying functions functional vs. imperative languages –store location –assignment statement vs. application of a function (expressions) side-effects aliasing referential transparency

© M. Winter COSC 4P41 – Functional Programming Features of functional languages usually strongly typed (modern languages) algebraic type definitions –mathematical based notation –no (implicit) pointers higher-order functions –can accept functions as parameters –can return functions as results recursion as a basic principle application of rewrite rule: –function call replaced by code body run-time overhead  garbage collection slogan: define “what to do”, not “how to do”

© M. Winter COSC 4P41 – Functional Programming What is a function? inputs output A functional program is basically a list of definitions of functions. + Int A function is something which produces an output value depending on the input value(s). A type is a collection of values. Usually functions are considered to take values of specific types as input, and produce values of another type.

© M. Winter COSC 4P41 – Functional Programming Definitions Haskell definitions are of the form: name :: type name = expression Examples: size :: Int size = (12+13)*4 square :: Int -> Int square n = n*n

© M. Winter COSC 4P41 – Functional Programming {-######################################################### FirstScript.hs Simon Thompson, June 1998 The purpose of this script is - to illustrate some simple definitions over integers (Int); - to give a first example of a script. #########################################################-} -- The value size is an integer (Int), defined to be -- the sum of twelve and thirteen. size :: Int size = The function to square an integer. square :: Int -> Int square n = n*n -- The function to double an integer. double :: Int -> Int double n = 2*n -- An example using double, square and size. example :: Int example = double (size - square (2+2))

© M. Winter COSC 4P41 – Functional Programming ########################################################### FirstLiterate.lhs Simon Thompson, June 1998 The purpose of this script is - to illustrate some simple definitions over integers (Int); - to give a first example of a literate script. ########################################################### The value size is an integer (Int), defined to be the sum of twelve and thirteen. > size :: Int > size = The function to square an integer. >square :: Int -> Int >square n = n*n The function to double an integer. >double :: Int -> Int >double n = 2*n An example using double, square and size. >example :: Int > example = double (size - square (2+2))

© M. Winter COSC 4P41 – Functional Programming The Booleans type Bool operations exOr :: Bool -> Bool -> Bool exOr x y = (x || y) && not (x && y) && and || or not

© M. Winter COSC 4P41 – Functional Programming The integers type Int : range – … type Integer : range unbounded operations + sum * product ^ raise to the power - difference div whole number division mod remainder abs absolute value negate change sign

© M. Winter COSC 4P41 – Functional Programming Relational operators and overloading (==) for integers and Booleans. This means that (==) will have the type Int -> Int -> Bool Bool -> Bool -> Bool Indeed t -> t -> Bool if the type t carries an equality. (==) :: Eq a => a -> a -> Bool > greater than >= greater than or equal to == equal to /= not equal to <= less than or equal to < less than

© M. Winter COSC 4P41 – Functional Programming The rational numbers type Rational (import Ratio) operations and +, *, -, negate, abs %Integer -> Integer -> Rational numerator the numerator denominator the denominator fromIntegerInteger -> Rational

© M. Winter COSC 4P41 – Functional Programming The characters type Char ‘a’ ‘\t’ tab ‘\n’ newline ‘\\’ backslash ‘\’’ single quote ‘\”’ double quote ‘\97’ character with ASCII code 97, i.e., ‘9’

© M. Winter COSC 4P41 – Functional Programming Layout mystery x = x*x +x +2 next x = … fun v1 v2 … vn | g1 = e1 | g2 = e2 … | otherwise = e r

© M. Winter COSC 4P41 – Functional Programming Operators and Do-it-yourself operators (+) :: Int -> Int -> Int (+) 2 3 = `max` 3 = max 2 3 Operator symbols !,#,$,%,&,*,+,.,/,,?,\,^,|,:,-,~ (&&&) :: Int -> Int -> Int x &&& y | x > y = y | otherwise = x