|
Miranda is a non-strict purely functional programming language developed by Professor 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, of which the word 'Miranda' is a trademark, it was the first purely functional language to be intended for use as a commercial tool rather than for academic purposes. In computer programming, lazy evaluation is a concept that attempts to minimize the work the computer has to do. ...
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions. ...
David A. Turner is a prominent British computer scientist. ...
SASL (from St. ...
KRC (Kent Recursive Calculator) is a lazy functional language developed by David Turner in 1981 based on SASL, with pattern matching and ZF expressions. ...
ML is a general-purpose functional programming language developed by Robin Milner and others in the late 1970s at Edinburgh University, whose syntax is inspired by ISWIM. Historically, ML stands for metalanguage as it was conceived to develop proof tactics in the LCF theorem prover (the language of which ML...
Hope is a small functional programming language, with strong polymorphic typing, algebraic types, pattern matching, and higher-order functions. ...
The solution to most example problems 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. 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...
APL (for A Programming Language, or sometimes Array Processing Language) is an array programming language based on a notation invented in the 1950s by Kenneth E. Iverson while at Harvard University. ...
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions. ...
It was first published in 1985, and only one interpreter was ever written for it, in C for Unix-flavour operating systems. The later Haskell programming language is similar in many ways to Miranda. The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the...
Haskell logo Haskell is a standardized pure functional programming language with non-strict semantics. ...
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. In computer programming, lazy evaluation is a concept that attempts to minimize the work the computer has to do. ...
Since the parsing algorithm makes intelligent use of layout (indentation), there is rarely a need for bracketing statements and no statement terminators are required. This feature is also used in Occam and Haskell and was popularized by Python. Occam (from William of Ockham of Occams Razor fame) is a parallel programming language that builds on Communicating Sequential Processes (CSP) and shares many of their features. ...
Haskell logo Haskell is a standardized pure functional programming language with non-strict semantics. ...
Python is an interpreted, interactive programming language created by Guido van Rossum in 1990, originally as a scripting language for Amoeba OS capable of making system calls. ...
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: infinite-precision integers (a.k.a. Bignums) by default, and regular floating-point values as required. A bignum package in a computer or program allows internal representation of very large integers, rational numbers, decimal numbers, or floating-point numbers (limitted only by available memory), and provides a set of arithmetic operations on such numbers. ...
Tuples are sequences of elements of potentially mixed types, analogous to records in Pascal-like languages, and are written delimited with parenthesis: this_employee = ("Folland, Mary", 10560, False, 35) 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: 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 comprehensions" (previously known as "ZF expressions"), which come in two main forms: an expression applied to a series of terms, e.g.: A list comprehension is a Haskell syntax that is similar to set comprehensions or set-builder notation, ie the notation In Haskell list comprehensions this would be written as S = [ x | x<-[0. ...
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 many other purely functional languages, functions are first-class citizens, which is to say that they can be passed as parameters 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" (curried) by supplying less than the full number of parameters. This gives another function which, given the remaining parameters, will return a result. For example: In computer science, currying is the technique of transforming a function taking multiple arguments into a function that takes a single argument (the first of the arguments to the original function) and returns a new function that takes the remainder of the arguments and returns the result. ...
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 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: 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) = [[x] ++ y | 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 - Official website
- Licensed public-access Unix system with Miranda
- Free infinite-precision scientific calculator in Miranda
See also |