| |||||||||
Miranda is a non-strict purely functional programming language developed by David Turner as a successor to his earlier programming languages Sasl and KRC, using some concepts from ML and Hope. Marketed by Research Software Ltd. of England, Miranda was the first purely functional language to be intended for use as a commercial tool rather than for academic purposes. The later Haskell programming language is similar in many ways to Miranda.
Miranda is purely functional, this is, it completely 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.
Although Miranda is a strongly-typed language, it does not enforce type declarations. As popularized by Python, the parsing algorithm makes intelligent use of layout: there is rarely a need for bracketing statements and no statement terminators are required. The notation for function application is simply juxtaposition, as in sin x.
The list 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 ++, substraction 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 of specifying an increment other than 1:
Tuples are sequences of elements of potentially mixed types, analogous to records in Pascal-like languages, and are written delimited with parenthesis:
The following Miranda script determines the set of all subsets of a set of numbers: