Talk:APL

From HaskellWiki
Revision as of 16:10, 9 March 2012 by RogerHui (talk | contribs) (added link to Vector article; minor format changes)
Jump to navigation Jump to search

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). 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.
Defined functions enjoy the same syntax as primitive functions.

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.
See http://www.youtube.com/watch?fmt=18&gl=GB&hl=en-GB&v=a9xAKttWgP4 for a flavour of 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