Functional Programming Lecture 1 - Introduction Professor Muffy Calder.

Slides:



Advertisements
Similar presentations
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Advertisements

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Copyright © by Curt Hill Expressions and Assignment Statements Part 2.
Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at:
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
String Escape Sequences
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
0 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
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.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CPS120: Introduction to Computer Science
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Copyright © – Curt Hill Types What they do.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CPS120: Introduction to Computer Science Variables and Constants.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Types Type Errors Static and Dynamic Typing Basic Types NonBasic Types
Midterm recap Total was 80 points Distribution range
Types CSCE 314 Spring 2016.
Theory of Computation Lecture 4: Programs and Computable Functions II
Boolean Data Lesson #1 Outline
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Lecture: MATLAB Chapter 1 Introduction
Representation, Syntax, Paradigms, Types
A lightening tour in 45 minutes
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
Type Systems Terms to learn about types: Related concepts: Type
Chapter 2.
Boolean Data Lesson #1 Outline
Building Java Programs Chapter 2
Introduction to Java, and DrJava part 1
College of Computer Science and Engineering
Representation, Syntax, Paradigms, Types
Introduction to Primitive Data types
Programming Languages 2nd edition Tucker and Noonan
High Level Programming Languages
Representation, Syntax, Paradigms, Types
Low Level Programming Languages
Introduction to Java, and DrJava
Representation, Syntax, Paradigms, Types
Summary of what we learned yesterday
Unit 3: Variables in Java
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
Introduction to Primitive Data types
Presentation transcript:

Functional Programming Lecture 1 - Introduction Professor Muffy Calder

About the Course the Haskell functional language Lectures + Laboratories + Problem Sessions 2 Assignments Web site –Lecture notes –Assignments and problem sheets –Resources Textbook Functional Programming in Haskell by Simon Thompson

Programming Languages imperative: Ada, C, Pascal, … object: Java, C++, Smalltalk … logic: Prolog,... functional: Haskell, ML, Lisp, Scheme, … –Haskell named after Haskell B. Curry –Not Schoenfinkel –Haskell is lazy –ML is strict

What is Functional Programming? Based on mathematical functions Example –A function to compute whether or not an integer is in a list of integers inlist :: Int -> [Int] -> Bool inlist x [] = False inlist x (y:ys) = | (x == y) = True | otherwise = inlist x ys inlist 3 [5,3,6] inlist 2 [5,3,6] Key concepts –Types –Recursion

Why use Functional Languages? Concise and powerful style Rapid prototyping Strong error checking by intepreter/compiler Reduced debugging time Reliable, correct software Formal reasoning Why teach it in second year? –Good discipline + more abstract way of thinking

Haskell Standard functional language –developed by international committee 3 people from GU on that committee Used as the basis for numerous projects, in numerous countries Has technical characteristics that support software engineering and formal methods

Hugs An interactive interpreter for Haskell98 –Hugs98 for windows Very quick ‘compilation’ and error checking Available on nearly all computers Free software See

Overview of Functional Programming 2 slogans everything is a function every function has a type FP consists of defining types defining functions applying functions and calculating the resulting expression f typed inputs typed output

Types, Constants and Expressions type - set of possible values Int constant - a particular value in a type 27:: Int expression - can be evaluated 2+3*x notation: 2+2 => 4 “2+2 evaluates to 4” The type of + is Int->Int-Int, i.e. _+_ :: Int->Int->Int

Int and Integer Int - 32-bit integers Integer - genuine integers –no limit on size (except memory) –all operations give correct result –programmer doesn’t have to worry about how much memory to allocate You will usually use Int.

Float and Double Single and double precision floating point numbers Does not give exact real arithmetic - there can be roundoff errors It is unlikely that you will use these types in this course.

Char ASCII characters constant - surround with single quote ‘x‘ :: Char can compare characters `c` < ‘Z’ case conversion –toUpper ‘ w ‘ => ‘ W ‘ –toLower ‘Q ‘ => ‘ q ‘ –toUpper :: Char -> Char

Bool Boolean values, used to control conditionals only two constants: False :: Bool and True :: Bool b && c (conjunction) b || c (disjunction) not b (negation) Example: ( 3 <= x) && (x <= 10) :: Bool

Function application Write the name of the function followed by the arguments Sometimes use terminology rator and rand Don’t put parentheses around the argument sqrt 9.0 fcn (sqrt x) * * (sqrt (pi*r*r)) + y E.g. In Maths f(x) In FP (f x)