Difference between revisions of "Talk:APL"

From HaskellWiki
Jump to navigation Jump to search
(First cut of a cultural introduction between APL and Haskell)
 
Line 5: Line 5:
 
Everything is an array. There is no access to underlying scalars!<br>
 
Everything is an array. There is no access to underlying scalars!<br>
 
NB: APL recycles the word "scalar" to mean rank-0 array.<br>
 
NB: APL recycles the word "scalar" to mean rank-0 array.<br>
NB: A matrix (rank-2 array) with 3 rows and 0 columns is distinct from one with 0 rows and 4 columns.<br>
+
NB: A matrix (rank-2 array) with 3 rows and 0 columns is distinct from one with 0 rows and 3 columns.<br>
 
NB: A length-0 character vector is distinct from a length-0 numeric vector.<br>
 
NB: A length-0 character vector is distinct from a length-0 numeric vector.<br>
 
<br>
 
<br>

Revision as of 18:25, 8 March 2012

APL for Haskell-ers (please improve)

Array: rectanglar collection of items arranged along 0 or more axes,
where an item is a number, a character or an array.
Everything is an array. There is no access to underlying scalars!
NB: APL recycles the word "scalar" to mean rank-0 array.
NB: A matrix (rank-2 array) with 3 rows and 0 columns is distinct from one with 0 rows and 3 columns.
NB: A length-0 character vector is distinct from a length-0 numeric vector.

Function: 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