Gc16 3011 functional programming lecture 4 miranda
This presentation is the property of its rightful owner.
Sponsored Links
1 / 12

GC16/3011 Functional Programming Lecture 4 Miranda PowerPoint PPT Presentation


  • 67 Views
  • Uploaded on
  • Presentation posted in: General

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!

Download Presentation

GC16/3011 Functional Programming Lecture 4 Miranda

An Image/Link below is provided (as is) to download presentation

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 programming lecture 4 miranda

GC16/3011 Functional ProgrammingLecture 4Miranda

(and her friend Amanda)


Contents

Contents

  • Miranda/Amanda

  • Amanda demonstration

  • Comments

  • Legal names and binding

  • Types and type checking

  • Tuples

  • Simple functions


Amanda

Amanda

  • 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


Amanda demonstration

Amanda Demonstration

  • 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


  • Amanda demonstration1

    Amanda Demonstration

    • Interpretive environment

    • Use it as a calculator

    • Simple definitions stored in a file

    • Main definition

    • Define and use functions


    Comments

    Comments

    • 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


    Legal names

    Legal names

    • 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

    • Names MUST start with an alphabetic character

    • Names MUST NOT start with a capital letter!

      • but may contain numbers and underscores


    Types

    Types

    • 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


    Type checking

    Type Checking

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


    Tuples

    Tuples

    • A simple data structure

    • (“Sheila Bloggs”, 23, “2 Turnabout Road, NW3”, 60, False)

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

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

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

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


    Simple functions

    Simple Functions

    inc x = x + 1

    || the hello function

    hello :: num -> [char]

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

    = “goodbye”, otherwise


    Summary

    Summary

    • Miranda/Amanda

    • Amanda demonstration

    • Comments

    • Legal names and binding

    • Types and type checking

    • Tuples

    • Simple functions


  • Login