ArticleslgStudy

mathematics

Miranda (programming language)

Miranda (programming language) is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Miranda (programming language) rather than just read about it. In short: Miranda is a lazy, purely functional programming language designed by David Turner as a successor to his earlier programming languages SASL and KRC, using some concepts from ML and Hope. It was produced by Research Software Ltd. of England (which holds a trademark on the name Miranda) and was the first purely functional language to be commercially supported.

Miranda (programming language) — main illustration
Miranda (programming language) — illustration

Key takeaways

  • Miranda (programming language) belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Miranda (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Miranda (programming language) from memory before moving on to harder problems.

Reference excerpt

Miranda is a lazy, purely functional programming language designed by David Turner as a successor to his earlier programming languages SASL and KRC, using some concepts from ML and Hope. It was produced by Research Software Ltd. of England (which holds a trademark on the name Miranda) and was the first purely functional language to be commercially supported. Miranda was first released in 1985 as a fast interpreter in C for Unix-flavour operating systems, with subsequent releases in 1987 and 1989. It had a strong influence on the later Haskell language. Turner stated that the benefits of Miranda over Haskell are: "Smaller language, simpler type system, simpler arithmetic". In 2020 a version of Miranda was released as open source under a BSD licence. The code has been updated to conform to modern C standards (C11/C18) and to generate 64-bit binaries. This has been tested on operating systems including Debian, Ubuntu, Solaris, Windows, WSL/Ubuntu and macOS(Catalina).

Name

The name Miranda is taken from the gerundive form of the latin verb miror, meaning "to be admired". The logo features a rendition by John William Waterhouse of the character Miranda from Shakespeare's The Tempest.

Overview Miranda is a lazy, purely functional programming language. That is, it lacks side effects and imperative programming features. A Miranda program (called a script) is a set of equations that define various mathematical functions and algebraic data types. The word set 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 algorithm makes intelligent use of layout (indentation, via off-side rule), bracketing statements are rarely needed and statement terminators are unneeded. This feature, inspired by ISWIM, is also used in occam and Haskell and was later popularized by Python. Commentary 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", in which every line is considered a comment unless it starts with a > sign. Miranda's basic data types 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 integers (a.k.a. bignums) by default, and regular floating point values as required. Tuples are groups of elements of potentially mixed types, in a fixed order, analogous to records in Pascal-like languages, but with unnamed fields. They are delimited with parentheses:

The list 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:

List concatenation is ++, subtraction is --, construction is :, sizing is # and indexing is !, so:

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:

More general and powerful list-building facilities are provided by "list comprehensions" (previously known as "ZF expressions"), which come in two main forms: an expression applied to a series of terms, e.g.:

(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.:

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 citizens, which is to say that they can be passed as arguments to other functions, returned as results, or included as elements of data structures. What is more, a function with two or more parameters may be "partially parameterised", or curried, by supplying fewer arguments than the full number of parameters. This gives another function which, given the remaining parameters, will return a result. For example:

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 with two parameters (operands) 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:

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

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, it does not insist on explicit type declarations. If a function's type is not explicitly declared, the interpreter infers 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:

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

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 defines the list of all sublists of a given list

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

Here, we have some more examples

References

External links Official website The currently maintained open source version of Professor Turner's interpreter for Miranda. The infinite precision math library, a large example of programming in Miranda (and Haskell).

Illustrations

Miranda (programming language): Miranda by John William Waterhouse, 1917
Miranda by John William Waterhouse, 1917

Worked examples

Example 1 — a first encounter with Miranda (programming language)

Start with the simplest possible case. Write down what Miranda (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Miranda (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Miranda (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Miranda (programming language)

In research
Miranda (programming language) appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Miranda (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Miranda (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Declarative programming languages, Functional languages, History of computing in the United Kingdom, so understanding it makes those chapters shorter.
In everyday life
Look for Miranda (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Miranda (programming language)” →

How to study Miranda (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Miranda (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Miranda (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Miranda (programming language) in simple terms?

Miranda is a lazy, purely functional programming language designed by David Turner as a successor to his earlier programming languages SASL and KRC, using some concepts from ML and Hope. It was produced by Research Software Ltd. of England (which holds a trademark on the name Miranda) and was the f…

Why does Miranda (programming language) matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Miranda (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Miranda (programming language).

Tags

  • Declarative programming languages
  • Functional languages
  • History of computing in the United Kingdom
  • Programming languages
  • Programming languages created in 1985

Keep exploring