Recent Articles



































Miranda programming language



         


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.

[Top]

Overview

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:

week_days = ["Mon","Tue","Wed","Thur","Fri"]

List concatenation is ++, substraction 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 of specifying an increment other than 1:

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

Tuples are sequences of elements of potentially mixed types, analogous to records in Pascal-like languages, and are written delimited with parenthesis:

this_employee = ("James, Mary", 10560, false, 35)
[Top]

Sample code

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

subsets [] = [[]] subsets [x:xs] = [[x] ++ y | y <- ys] ++ ys where ys = subsets xs
[Top]




  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License