Functional Programming Lecture 1 Introduction - PowerPoint PPT Presentation

About This Presentation
Title:

Functional Programming Lecture 1 Introduction

Description:

Hugs. An interactive interpreter for Haskell98. Hugs98 for windows ... See http://haskell.org/hugs. Overview of Functional Programming. 2 slogans ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 15
Provided by: muffyc
Category:

less

Transcript and Presenter's Notes

Title: Functional Programming Lecture 1 Introduction


1
Functional ProgrammingLecture 1 - Introduction
  • Professor Muffy Calder

2
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

3
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

4
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 -gt Int -gt Bool
  • inlist x False
  • inlist x (yys) (x y) True
  • otherwise
    inlist x ys
  • inlist 3 5,3,6
  • inlist 2 5,3,6
  • Key concepts
  • Types
  • Recursion

5
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

6
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

7
Hugs
  • An interactive interpreter for Haskell98
  • Hugs98 for windows
  • Very quick compilation and error checking
  • Available on nearly all computers
  • Free software
  • See http//haskell.org/hugs

8
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

typed inputs
typed output
f
9
Types, Constants and Expressions
  • type - set of possible values
  • Int
  • constant - a particular value in a type
  • 27 Int
  • expression - can be evaluated
  • 23x
  • notation 22 gt 4
  • 22 evaluates to 4
  • The type of is Int-gtInt-Int, i.e.
  • __ Int-gtInt-gtInt

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

11
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.

12
Char
  • ASCII characters
  • constant - surround with single quote x
    Char
  • can compare characters
  • c lt Z
  • case conversion
  • toUpper w gt W
  • toLower Q gt q
  • toUpper Char -gt Char

13
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 lt x) (x lt 10) Bool

14
Function application
  • Write the name of the function followed by the
    arguments
  • Sometimes use terminology rator and rand
  • Dont put parentheses around the argument
  • sqrt 9.0
  • fcn 2 8 13
  • 3.4 (sqrt x) 100
  • 2 (sqrt (pirr)) y
  • E.g. In Maths f(x)
  • In FP (f x)
Write a Comment
User Comments (0)
About PowerShow.com