All Topics  
Miranda programming language

 

   Email Print
   Bookmark   Link






 

Miranda programming language



 
 
Miranda is a non-strict
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 purely functional
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 designed by David Turner
David Turner (computer scientist)

Professor David Turner is a United Kingdom computer scientist.He has a D.Phil. from the University of Oxford. He has held professorships at Queen Mary, University of London, University of Texas at Austin and the University of Kent, where he now retains the post of Emeritus Professor....
 as a successor to his earlier programming languages SASL
SASL programming language

SASL is a purely functional programming programming language developed by David Turner at the University of St Andrews in 1972, based on the applicative subset of ISWIM....
 and KRC
KRC

KRC may stand for:* Kent Recursive Calculator, a functional programming language* Korean Resource Center, a grassroots nonprofit organization in Los Angeles, CA, US...
, using some concepts from ML and Hope. A product of Research Software Ltd. of England, of which the word 'Miranda' is a trademark, it was the first purely functional language to be commercially supported.

The solution to most example problems
Toy problem

In mathematics and information science, a toy problem is a problem that is not of immediate scientific interest, yet is used as an expository device to illustrate a trait that may be shared by other, more complicated, instances of the problem, or as a way to explain a particular, more general, problem solving technique....
 is briefer and simpler in Miranda than in most mainstream programming languages except maybe APL, and, like other functional languages, its users report that it enables them to produce more reliable programs with shorter development times than with the imperative programming languages they had previously used.

It was first released in 1985, as a fast interpreter in C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 for Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
-flavour operating systems, with subsequent releases in 1987 and 1989.






Discussion
Ask a question about 'Miranda programming language'
Start a new discussion about 'Miranda programming language'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Miranda is a non-strict
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 purely functional
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 designed by David Turner
David Turner (computer scientist)

Professor David Turner is a United Kingdom computer scientist.He has a D.Phil. from the University of Oxford. He has held professorships at Queen Mary, University of London, University of Texas at Austin and the University of Kent, where he now retains the post of Emeritus Professor....
 as a successor to his earlier programming languages SASL
SASL programming language

SASL is a purely functional programming programming language developed by David Turner at the University of St Andrews in 1972, based on the applicative subset of ISWIM....
 and KRC
KRC

KRC may stand for:* Kent Recursive Calculator, a functional programming language* Korean Resource Center, a grassroots nonprofit organization in Los Angeles, CA, US...
, using some concepts from ML and Hope. A product of Research Software Ltd. of England, of which the word 'Miranda' is a trademark, it was the first purely functional language to be commercially supported.

The solution to most example problems
Toy problem

In mathematics and information science, a toy problem is a problem that is not of immediate scientific interest, yet is used as an expository device to illustrate a trait that may be shared by other, more complicated, instances of the problem, or as a way to explain a particular, more general, problem solving technique....
 is briefer and simpler in Miranda than in most mainstream programming languages except maybe APL, and, like other functional languages, its users report that it enables them to produce more reliable programs with shorter development times than with the imperative programming languages they had previously used.

It was first released in 1985, as a fast interpreter in C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 for Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
-flavour operating systems, with subsequent releases in 1987 and 1989. The later Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
 programming language is similar in many ways to Miranda.

Overview

Miranda is a lazy
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
, purely functional
Purely functional

Purely functional is a term in computing used to describe algorithms, data structures or programming languages that exclude destructive modifications ....
 programming language. That is, it lacks side effect
Side effect (computer science)

In computer science, a subroutine or expression is said to produce a side effect if it modifies some state_ in addition to returning a value. For example, a function might modify a global or a static variable, modify one of its arguments, write data to a display or file, or read some data from other side-effecting functions....
s and imperative programming
Imperative programming

In computer science, imperative programming is a programming paradigm that describes computation in terms of statement s that change a program state ....
 features. A Miranda program (called a script) is a set of equation
Equation

An equation is a mathematics Proposition, in table of mathematical symbols, that two things are exactly the same . Equations are written with an equal sign, as in...
s that define various mathematical function
Function (mathematics)

The mathematical concept of a function expresses dependence between two quantities, one of which is known and the other which is produced. A function associates a single output to each input element drawn from a fixed Set , such as the real numbers , although different inputs may have the same output....
s and algebraic data type
Algebraic data type

In computer programming, an algebraic data type is a datatype each of whose value s is data from other datatypes wrapped in one of the constructors of the datatype....
s. The word set
Set

A set is a collection of distinct objects, considered as an object in its own right. Sets are one of the most fundamental concepts in mathematics....
 is important here: the order of the equations is, in general, irrelevant, and there is no need to define an entity prior to its use.

Since the parsing
Parsing

In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a sequence of lexical analysis#Token to determine their grammatical structure with respect to a given formal grammar....
 algorithm makes intelligent use of layout
Off-side rule

A computer programming language is said to adhere to the off-side rule if in it the scope of declarations is expressed by their indentation, i.e., blocks are formed via indentation....
 (indentation), there is rarely a need for bracketing statements and no statement terminators are required. This feature, inspired by ISWIM
ISWIM

ISWIM is an abstract computer programming language devised by Peter J. Landin and first described in his article, The Next 700 Programming Languages, published in the Communications of the ACM in 1966....
 is also used in occam
Occam (programming language)

occam is a Concurrent computing programming language that builds on the Communicating Sequential Processes process algebra, and shares many of its features....
 and Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
 and was later popularized by Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
.

Comment
Comment (computer programming)

In computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program....
ary is introduced into regular scripts by the characters || and continue to the end of the same line. An alternative commenting convention affects an entire source code file, known as a "literate script
Literate programming

Literate programming is an approach to programming which was introduced by Donald Knuth. Knuth conceived literate programming as an alternative to the structured programming paradigm of the 1970s....
", in which every line is considered a comment unless it starts with a > sign.

Miranda's basic data type
Data type

A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it....
s are char, num and bool. A character string is simply a list of char, while num is silently converted between two underlying forms: arbitrary-precision
Arbitrary-precision arithmetic

In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, is a technique whereby computer programs perform calculations on integers or rational numbers with an arbitrary number of numerical digits of precision , typically limited only by the available memory of the host system....
 integers (a.k.a. bignums) by default, and regular floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
 values as required.

Tuple
Tuple

In mathematics, a tuple is a sequence of a specific number of values, called the components of the tuple. These components can be any kind of mathematical objects, where each component of a tuple is a value of a specified type....
s are sequences of elements of potentially mixed types, analogous to record
Record (computer science)

In computer science, a record type or struct is a type whose values are records, i.e. aggregates of several items of possibly different types....
s in Pascal
Pascal (programming language)

Pascal is an influential imperative programming and Procedural programming programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structure....
-like languages, and are written delimited with parenthesis: this_employee = ("Folland, Mary", 10560, False, 35)

The list
List (computing)

In computer science, a list is an ordered Multiset of entity/items.In the context of object-oriented programming languages, a list is defined as an instance of an abstract data type , formalizing the concept of an order theoryed Collection class of entity....
 instead is the most commonly used data structure in Miranda. It is written delimited by square brackets and with comma-separated elements, all of which must be of the same type:

week_days = ["Mon","Tue","Wed","Thur","Fri"] List concatenation is ++, subtraction is --, construction is :, sizing is # and indexing is !, so:

days = week_days ++ ["Sat","Sun"] days = "Nil":days days!0 ? "Nil" days = days -- ["Nil"] #days ? 7

There are several list-building shortcuts: .. is used for lists whose elements form an arithmetic series, with the possibility for specifying an increment other than 1:

fac n = product [1..n] odd_sum = sum [1,3..100]

More general and powerful list-building facilities are provided by "list comprehension
List comprehension

A list comprehension is a Syntax of programming languages construct available in some programming languages for creating a list based on existing lists....
s" (previously known as "ZF expressions"), which come in two main forms: an expression applied to a series of terms, e.g.:

squares = [ n * n | n <- [1..] ]

(which is read: list of n squared where n is taken from the list of all positive integers) and a series where each term is a function of the previous one, e.g.:

powers_of_2 = [ n | n <- 1, 2*n .. ]

As these two examples imply, Miranda allows for lists with an infinite number of elements, of which the simplest is the list of all positive integers: [1..]

The notation for function application is simply juxtaposition, as in sin x.

In Miranda, as in most other purely functional languages, functions are first-class
First-class function

In computer science, a programming language is said to support first-class functions if it treats function s as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning the...
 citizens, which is to say that they can be passed as parameter
Parameter (computer science)

In computer programming, a parameter is a special kind of variable#In_computer_programming that refers to data that a subroutine receives to operate on....
s to other functions, returned as results, or included as elements of data structures. What is more, a function requiring two or more parameters may be "partially parameterised", or curried
Currying

In computer science, currying, invented by Moses Sch?nfinkel and Gottlob Frege, and independently by Haskell Curry, is the technique of transforming a function that takes multiple parameter in such a way that it can be called as a chain of functions each with a single argument....
, by supplying less than the full number of parameters. This gives another function which, given the remaining parameters, will return a result. For example:

add a b = a + b increment = add 1

is a roundabout way of creating a function "increment" which adds one to its argument. In reality, add 4 7 takes the two-parameter function add, applies it to 4 obtaining a single-parameter function that adds four to its argument, then applies that to 7.

Any function taking two parameters can be turned into an infix operator (for example, given the definition of the add function above, the term $add is in every way equivalent to the + operator) and every infix operator taking two parameters can be turned into a corresponding function. Thus:

increment = (+) 1

is the briefest way to create a function that adds one to its argument. Similarly, in

half = (/ 2) reciprocal = (1 /)

two single-parameter functions are generated. The interpreter understands in each case which of the divide operator's two parameters is being supplied, giving functions which respectively divide a number by two and return its reciprocal.

Although Miranda is a strongly-typed programming language
Strongly-typed programming language

In computer science and computer programming, the term strong typing is used to describe those situations where programming languages specify one or more restrictions on how operations involving values having different data types can be intermixed....
, it does not insist on explicit type declaration
Declaration (computer science)

In programming languages, a declaration specifies the identifier, Type system, and other aspects of language elements such as Variable#Computer_programming and Subroutine....
s. If a function's type is not explicitly declared, the interpreter infer
Type inference

Type inference, or implicit typing, refers to the ability to deduce automatically the type of a value in a programming language. It is a feature present in some strongly-typed programming language static typing#Static and dynamic typing languages....
s it from the type of its parameters and how they are used within the function. In addition to the basic types (char, num, bool), it includes an "anything" type where the type of a parameter does not matter, as in the list-reversing function:

rev [] = [] rev (a:x) = rev x ++ [a]

which can be applied to a list of any data type, for which the explicit function type declaration would be:

rev [*] -> [*]

Finally, it has mechanisms for creating and managing program modules whose internal functions are invisible to programs calling those modules.

Sample code


The following Miranda script determines the set of all subsets of a set of numbers

subsets [] = subsets (x:xs) = y <- ys] ++ ys where ys = subsets xs

and this is a literate script for a function primes which gives the list of all prime numbers

> || The infinite list of all prime numbers, by the sieve of Eratosthenes.

The list of potential prime numbers starts as all integers from 2 onwards; as each prime is returned, all the following numbers that can exactly be divided by it are filtered out of the list of candidates.

> primes = sieve [2..] > sieve (p:x) = p : sieve [n | n <- x; n mod p ~= 0]

External links