[ ^ CSE 341 | section index | next -->]

CSE 341 -- 11 May. 2000


Functional programming

In Programming Languages: Concepts and Constructs, Ravi Sethi quotes J.H. Morris, who writes:

Functional programming as a minority discipline in the field of programming languages bears a certain resemblance to socialism in its relation to conventional, capitalist economic doctrine. Their proponents are often brilliant intellectuals perceived to be radical and rather unrealistic by the mainstream, but little-by-little changes are made in conventional languages and economies to incorporate features of the radical proposals.

Miranda types

Miranda has the standard primitive types (number, char, boolean) and a number of methods of composing those types (lists, tuples, "algebraic" types):

3:: => num "foo":: => [char] (3, [5, 6, 7], 'a', "b"):: => (num, [num], char, [char])

Most functional languages are really kind of a dressed up "Lisp with types". They typically add syntactic complications in the name of making things simpler. Functions in Miranda are defined using "pattern matching":

add 0 y = y add x y = 1 + (add (x - 1) y)

Patterns are matched in the sequence in which they appear. Functions may also use guards, which in defiance of virtually every other programming language's convention are written after the clause to which they apply:

add x y = y , if x = 0 = 1 + (add (x - 1) y) , otherwise

Last modified: Wed May 10 20:37:32 PDT 2000