[erlang-questions] Erlang math libraries
Thu May 17 02:38:03 CEST 2007
On 16 May 2007, at 3:52 pm, jm wrote:
> I'd sneek a look at how lisp or haskell handle matrices to get some
I wouldn't bother.
Lisp: aside from some header information, Lisp handles arrays EXACTLY
like C and Fortran. In particular, to add 1 to every element of an
array of numbers,
(do ((i 0 (1+ i))) ; for i := 0 then i+1
((>= i n)) ; until i >= n do
(setf (aref a i) ; a[i] :=
(+ 1 (aref a i)))) ; 1 + a[i]
You can specify the element type of a Lisp array, so you can have
arrays of unboxed elements. With careful use of Lisp type annotations,
you can (with a good Lisp compiler) avoid all boxing of intermediates,
and basically end up with the kind of performance you would expect from
a good native code Java compiler.
Haskell has support for immutable arrays -- Array indextype
but it is so general that the overheads are unpleasantly high. (For
example, multidimensional arrays are normally accessed using tuples
as subscripts.) There are widely accepted libraries, which are not,
however, part of the "standard", which include "state transformation"
monads providing mutable variables tamed to fit in a pure functional
language, and those libraries include unboxed arrays -- but still with
the exceed generality for subscripts.
Erlang of course does have tuples, which are immutable simple vectors.
More information about the erlang-questions