Miranda Programming Language By Bindu H. Vinay. History of Miranda  Miranda was developed in 1985-86 by David Turner  It is currently being marketed.

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Regular Expressions, Backus-Naur Form and Reverse Polish Notation.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Miranda – A Functional Language By Dan Vasicek 2009/11/15.
Introduction to C Programming
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
FUNCTIONAL PROGRAMMING IN ERLANG ID1218 Lecture Christian Schulte Software and Computer Systems School of Information and.
C++ for Engineers and Scientists Third Edition
Introduction to C Programming
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
A First Book of ANSI C Fourth Edition
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)
Formal Models of Computation Part II The Logic Model
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
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.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
CPS120: Introduction to Computer Science
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Advanced Functional Programming 2009 Ulf Norell (lecture by Jean-Philippe Bernardy)
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 9: Functional Programming in a Typed Language.
Functional Programming With examples in F#. Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands.
Com Functional Programming Regular Expressions and Abstract Data Types Marian Gheorghe Lecture 14 Module homepage Mole &
Overview of the Haskell 98 Programming Language
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
1 ICS103 Programming in C Lecture 8: Functions I.
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
Haskell. 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.
An introduction to functional programming using Haskell CENG242 –Recitation 1.
1 PROGRAMMING IN HASKELL Lecture 2 Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
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)
Advanced Functional Programming 2010
Functional Programming
Fundamentals of Programming I Overview of Programming
CS314 – Section 5 Recitation 10
Midterm recap Total was 80 points Distribution range
Types CSCE 314 Spring 2016.
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
RECURSION.
ML: a quasi-functional language with strong typing
Theory of Computation Lecture 4: Programs and Computable Functions II
Chapter 3 Assignment and Interactive Input.
PROGRAMMING IN HASKELL
A lightening tour in 45 minutes
More Functional Programming
The Selection Structure
Haskell.
CSE 3302 Programming Languages
Arrays, For loop While loop Do while loop
Introduction to C++ Programming
Type & Typeclass Syntax in function
CSCE 314: Programming Languages Dr. Dylan Shell
Python Primer 1: Types and Operators
Haskell Types, Classes, and Functions, Currying, and Polymorphism
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Functional Programming and Haskell
Theory of Computation Lecture 4: Programs and Computable Functions II
An Overview of C.
PROGRAMMING IN HASKELL
Functional Programming and Haskell
Presentation transcript:

Miranda Programming Language By Bindu H. Vinay

History of Miranda  Miranda was developed in by David Turner  It is currently being marketed by Research Software Ltd. of England.  It is currently being marketed by Research Software Ltd. of England.  Miranda was the successor of the functional languages SASL and KRC.  Miranda was the successor of the functional languages SASL and KRC.  The main goal for creating Miranda was to produce a commercial version of a standard non- strict purely functional language.  The main goal for creating Miranda was to produce a commercial version of a standard non- strict purely functional language.  The development environment is very flexible and easy-to-use.

Language Features  Non-Strict: In Non-Strict functional languages, the arguments to a function are not evaluated until they are actually required within the functions being called.  Non-Strict: In Non-Strict functional languages, the arguments to a function are not evaluated until they are actually required within the functions being called.  Any parameter can be passed to a function and until it is needed in that function, this parameter is not evaluated. This is also known as lazy evaluation.  The main advantage of using this method is that it allows for passing infinite element data structures to a function.

Language Features  Purely Functional: Pure functional languages perform all computation using function application.  Purely Functional: Pure functional languages perform all computation using function application.  "Side-effect" features such as destructive assignments and looping are not even provided within the language.  All programs have to strictly adhere to the functional approach of programming.

Language Features  Miranda runs under the UNIX operating system.  The aim of the Miranda system is to provide a modern functional language, embedded in an industrial quality programming environment.

Miranda Environment  The Miranda system is interactive and runs under UNIX as a self contained subsystem.  The basic action is to evaluate expressions, supplied by the user at the terminal, in the environment established by the current script.

Miranda Environment  The Miranda compiler works in conjunction with an editor (normally this is "vi" but it can be set to any editor of the users choice) and scripts are automatically recompiled after edits, and any syntax or type errors signaled immediately.  The system permits a high proportion of logical errors to be detected at compile time.

Miranda Environment  There is quite a large library of standard functions.  There is a good interface to UNIX, permitting Miranda programs to take data from, and send data to, arbitrary UNIX files.  It is also possible to invoke Miranda programs directly from the UNIX shell, and to combine them, via UNIX pipes, with processes written in other languages.

Miranda – Areas of Application  Rapid prototyping  Teaching functional programming  As a specification language  Research into functional programming  A general purpose programming tool

Basic Concepts of Miranda  A program or script as it is called by Miranda programmers, is a collection of equations defining various functions and data structures which we are interested in computing.  The order in which the equations are given is not significant.  The order in which the equations are given is not significant.  There is for example no obligation for the definition of an entity to precede its first use.  Miranda as a language is terse.

Basic Concepts of Miranda  There are no mandatory type declarations, although the language is strongly typed.  There are no mandatory type declarations, although the language is strongly typed.  There are no semicolons at the end of definitions - the parsing algorithm makes intelligent use of layout.

Simple Program Example z = sq x / sq y sq n = n * n x = a + b y = a - b a = 10 b = 5 z = sq x / sq y sq n = n * n x = a + b y = a - b a = 10 b = 5  As you can see, there is no order in the way the statements are defined.  The function sq is defined as shown, there are no parenthesis etc. n is the formal parameter.

Expressions and Assignments  Assignment statements are simply defined using the = sign.  Example: x = a + b

Data Structures  The most useful three data structures of Miranda are: Lists Tuples Tuples Laws Laws

Lists  A List is defined as a set of homogeneously typed values.  A List is defined as a set of homogeneously typed values.  The list data structure is an extremely powerful feature of Miranda.  The list data structure is an extremely powerful feature of Miranda.  It allows quick and simple list processing and also allows infinite lists. Example: week_days = ["Mon","Tue","Wed","Thur","Fri"]

Operations on Lists ++ Operation – This is used to add items at the end of the list. Example: days = week_days ++ ["Sat","Sun"] -- Operation – This is used to subtract items from the end of the list. Example: noMondays = week_days -- [“Mon”] Example: noMondays = week_days -- [“Mon”] : - This operation prefixes an element to the front of a list. Example: 0:[1,2,3] has the value [0,1,2,3] Example: 0:[1,2,3] has the value [0,1,2,3] # - This operation returns the length of a list Example: #days is 7 Example: #days is 7 ! – This operation does subscripting Example: days!0 is "Mon" Example: days!0 is "Mon"

Tuples  It is a non-homogenous sequence of values which can be utilized to form enumerated data types or even form complex data structures such as records.  In other words, a sequence of elements of mixed type is called a Tuple, and is written using parentheses instead of square brackets. Example: employee = ("Jones",True,False,39)

Guarded Equations  An equation can have several alternative right hand sides distinguished by "guards" - written on the right following a comma.  An equation can have several alternative right hand sides distinguished by "guards" - written on the right following a comma.  For example: –The greatest common divisor function can be written as: gcd a b = gcd (a-b) b, if a>b = gcd a (b-a), if a b = gcd a (b-a), if a<b = a, if a=b

Where Clause  It is also permitted to introduce local definitions on the right hand side of a definition, by means of a "where" clause.  It is also permitted to introduce local definitions on the right hand side of a definition, by means of a "where" clause. –For Example: –Definition of a function for solving quadratic equations (it either fails or returns a list of one or two real roots): – quadsolve a b c = error "complex roots", if delta 0 where delta = b*b - 4*a*c radix = sqrt delta

Pattern Matching  It is permitted to define a function by giving several alternative equations, distinguished by the use of different patterns in the formal parameters.  It is permitted to define a function by giving several alternative equations, distinguished by the use of different patterns in the formal parameters.  This provides another method of doing case analysis which is often more elegant than the use of guards.  This provides another method of doing case analysis which is often more elegant than the use of guards. –For example: fac 0 = 1 fac (n+1) = (n+1)*fac n fac 0 = 1 fac (n+1) = (n+1)*fac n

Pattern Matching – More Examples –Example 1: fib 0 = 0 fib 1 = 1 fib (n+2) = fib (n+1) + fib n fib 0 = 0 fib 1 = 1 fib (n+2) = fib (n+1) + fib n –Example 2: On Lists sum [] = 0 sum (a:x) = a + sum x sum [] = 0 sum (a:x) = a + sum x -Example 3: On Tuples first (a,b) = a second (a,b) = b first (a,b) = a second (a,b) = b

Higher Order Functions  Miranda is a fully higher order language - functions can be both passed as parameters and returned as results.  Function application is left associative, so when we write "f x y" it is parsed as “(f x) y”

List Comprehensions  List comprehensions give a concise syntax for a rather general class of iterations over lists.  The syntax is adapted from an analogous notation used in set theory (called "set comprehension").  The syntax is adapted from an analogous notation used in set theory (called "set comprehension"). –Example: [ n*n | n <- [1..100] ]

Lazy Evaluation and Infinite Lists  Miranda's evaluation mechanism is "lazy", in the sense that no sub-expression is evaluated until its value is known to be required.  Miranda's evaluation mechanism is "lazy", in the sense that no sub-expression is evaluated until its value is known to be required.  One consequence of this is that is possible to define functions which are capable of returning an answer even if one of their arguments is undefined.  The other main consequence of lazy evaluation is that it makes it possible to write down definitions of infinite data structures. –Examples naturals = [0..] odds = [1,3..] squares = [ n*n | n <- [0..] ]

Polymorphic Strong Typing  Miranda is strongly typed i.e., every expression and every subexpression has a type, which can be deduced at compile time, and any inconsistency in the type structure of a script results in a compile-time error.  Type declaration is not required. The compiler is always able to deduce the type of an identifier from its defining equation.

Primitive Types  There are three primitive types –Num -> Integers and Floating Points –Bool -> True and False –Char -> Ascii character set Examples: [[1,2],[2,3],[4,5]] is of type [[num]] String “hello” is actually a list ['h','e','l','l','o'] Tuple (True,"hello",36) is of type (bool,[char],num)

User Defined Types  The user may introduce new types.  This is done by an equation in "::=“ –Example: tree ::= Nilt | Node num tree tree Nilt – atomic constructor Node – takes 3 params  Type Synonyms can be defined using == –Example: string == [char]

Abstract Data Types  By using “Abstype” and “with” –Stack implementation  abstype stack * with empty :: stack * isempty :: stack * -> bool push :: * -> stack * -> stack * pop :: stack * -> stack * top :: stack * -> *  stack * == [*] empty = [] push a x = (a:x) pop (a:x) = x top (a:x) = a

Conclusion  Miranda is a strong-typed non-strict functional language that is useful for rapid prototyping.  It is mainly implemented on Unix systems.  Provides some useful data types such as Lists and Tuples.