OCAMl a more natural extension language for python?

beliavsky at aol.com beliavsky at aol.com
Mon Jan 17 09:54:43 EST 2005


Jelle Ferringa wrote:

>Since I haven't got actual experience programming CAML I'd like to
speculate
>that OCAML would be a very pythonic way of extending python: its
>open-source, object oriented, as fast as C, and ! garbage collecting!

The open source g95 Fortran 95 compiler is already usable and will be
officially released this year. Fortran and C are comparable in speed,
and if one uses allocatable arrays rather than pointers, memory leaks
should not occur. Fortran 2003 supports OOP with inheritance, and a few
F95 compilers already have this functionality.

>That's depending on how you compare; I find OCAML quite readable
compared to C / Fortran .

Have you ever used Fortran 90 or 95?

I don't use OCAML, so I looked at some OCAML code to multiply matrices
at
http://shootout.alioth.debian.org/benchmark.php?test=matrix&lang=ocaml&id=0&sort=cpu
from the Computer Language Shootout . To create a matrix the OCAML code
is

7 let mkmatrix rows cols =
8   let count = ref 1 and last_col = cols - 1
9   and m = Array.make_matrix rows cols 0 in
10   for i = 0 to rows - 1 do
11     let mi = m.(i) in
12     for j = 0 to last_col do mi.(j) <- !count; incr count done;
13   done;

In Python with Numeric it's just

x = zeros([nrow,ncol],Float)

and in Fortran 90/95 it's just

real, allocatable :: x(:,:)
allocate (x(nrow,ncol))

There appears not to be a built-in function for matrix multiplication
in OCAML. There is in Python with Numeric or Numarray or Fortran 90/95.
For problems where the main data structures are arrays, OCAML seems to
be considerably more low-level than Python with Numeric/Numarray or
Fortran 90/95. Also, there exists a vast computational infrastructure
in Fortran and C (see http://www.netlib.org). Does OCAML have this?




More information about the Python-list mailing list