1 / 12

# GC16/3011 Functional Programming Lecture 4 Miranda - PowerPoint PPT Presentation

GC16/3011 Functional Programming Lecture 4 Miranda. (and her friend Amanda). Contents. Miranda/Amanda Amanda demonstration Comments Legal names and binding Types and type checking Tuples Simple functions. Amanda. PC version of Miranda Almost (but not quite) the same!

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' GC16/3011 Functional Programming Lecture 4 Miranda' - varen

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### GC16/3011 Functional ProgrammingLecture 4Miranda

(and her friend Amanda)

• Miranda/Amanda

• Amanda demonstration

• Legal names and binding

• Types and type checking

• Tuples

• Simple functions

• PC version of Miranda

• Almost (but not quite) the same!

• Get it from the Web pages

• http://www.cs.ucl.ac.uk/teaching/3C11/index.html

• Amanda204:

• http://www.engineering.tech.nhl.nl/engineering/personeel/bruin/data/amanda204.zip

• Lambda Calculus

• (3 + 4) * (6 + 7)

• But you can gives names to (sub)expressions

• x = 3 + 4

• y = 6 + 7

• main = (x * y)

• Also give names to functions (no lambdas!)

• inc x = x + 1

• main = inc 56

• Interpretive environment

• Use it as a calculator

• Simple definitions stored in a file

• Main definition

• Define and use functions

• VERY important!

• Use them from the start

• Example:

|| a simple definition for some text:

message = “hello mum”

|| here is a function which adds one to a number:

inc x = x + 1

• BINDING:

• NAME = EXPRESSION

• Funcname argname = EXPRESSION

• Binds funcname when defined (static)

• Binds argname when applied to an argument (dynamic)

• Each binding is unique, within specified scope

• Scope of argname is the function body (only)

• Nested scopes (see later) permit nested bindings for same name

• but may contain numbers and underscores

• Data can be, for example:

• Numbers (42): num

• Characters (‘A’): char

• Text (“strings”): [char]

• Truth values (True, False): bool

• Functions (f x = x + 1): arg_type -> result_type

• Miranda/Amanda allows us to CATEGORISE data into specific types

• Helps organise programs better

• Helps detect errors

• Done before the program is run

• Checks that operators (e.g. +) are executed on data of the correct type

• Checks that functions are applied to data of the correct type

• You can ask “what type is this?”

• You can specify “this is a Boolean value” etc.

• A simple data structure

• (34, True) :: (num, bool)

• (34, True) DOES NOT EQUAL (True, 34)

• (“increment”, (+ 1), inc)

:: ([char], num->num, num->num)

inc x = x + 1

|| the hello function

hello :: num -> [char]

hello x = “good morning”, if (x<10)

= “goodbye”, otherwise

• Miranda/Amanda

• Amanda demonstration