Array languages, such as APL, J and K, seem to be characterised by:
- Having a very simple and uniform syntax.
- Employing a terse lexical style.
- Making all primitive functions take and return whole arrays.
- Hiding from the programmer implementation details such as internal numeric types.
Array language proponents claim that these properties have a profound effect on productivity, freeing up the programmer to think at a higher level by avoiding the distractions of several levels of programming minutiae.
APL for Haskell-ers
Arrays: rectanglar collection of items arranged along 0 or more axes, where an item is a number, a character or an array. The rank of an array is its number of axes (dimensions); the shape of an array is a vector of its axis lengths.
Everything is an array. There is no access to underlying scalars!
Arrays of non-uniform type are used to model tuples.
- APL recycles the word scalar to mean rank-0 array; vector and matrix are used for arrays of rank 1 and 2 respectively.
- A matrix with 3 rows and 0 columns is distinct from one with 0 rows and 3 columns.
- A length-0 character vector is distinct from a length-0 numeric vector.
The article What is an Array? in the APL Journal Vector talks more about this topic.
Functions: infix, associate right with equal precedence.
Functions consume array "arguments" and return array results.
A "monadic" function is one that takes only a right argument.
Operators: infix, associate left with equal precedence.
Operators bind with array or function "operands" to form functions.
A monadic operator takes only a left operand.
Operator-operand binding is stronger than function-argument binding.
APL has only a single level of high-order function.
There is a rich set of primitive functions and operators.
Defined functions and operators enjoy the same calling syntax as their primitive counterparts.
See YouTube: Conway's Game of Life in APL and A Sudoku Solver in APL for a flavour of APL
- Notation as a Tool of Thought, Ken Iverson's 1979 Turing Award Lecture
- k programming language
- J programming language
- J Wiki Essays, examples of using J
- D-Functions Dyalog APL samples and musings
- TryAPL play with APL
Haskell for APL-ers (please improve)
Haskell is a pure, strongly-typed, lazy functional language. A function's result is determined only by its arguments and there are no side-effects.
While APL has only arrays, Haskell has:
- Lists: [1, 2, 3]
- Tuples: (2.3, "Haskell")
and arbitrarily high high-order functions. The syntax allows functions to take functions as arguments and to return them as results, so it doesn't need APL's distinction between functions and operators.
Unlike APL's arrays, the items of a list must all be of the same type, so you can't, for example, have a list whose first item is a number and its second a character string. There is exactly one flavour of empty list: .
We can combine the above structures to form lists-of-tuples; tuples-of-lists-of-functions; and so on.
The term "monadic" in Haskell bears no relation to its use in APL as a function with only a right argument.
The GHC Haskell compiler is able to represent vectors in contiguous memory locations and so access items in O(1) time.
See ???????? for a flavour of Haskell