What Programming Languages Should You Learn Next?

Paul Rubin http
Fri Mar 21 05:19:05 CET 2008

"Terry Reedy" <tjreedy at udel.edu> writes:
> What would be amazing would be a algorithm that could rewrite the 
> external-arrays Haskell/Python code to the equivalent of the in-place C 
> code. 

I don't think JHC (a fancy optimizing Haskell compiler) goes quite
that far, but it compiles Haskell to C code that looks pretty much
the same as imperative code that a careful programmer would write.

> Can one even write such an equivalent in Haskell?  (If it is purely 
> functional, then no, though one obviously can in Python.)

Yes, you can write in an imperative styld while staying purely
functional.  The trick is to notice that 
   b = f(a)
   c = g(b)
   d = h(c)
requires evaluating f,g,h in exactly that order.  So you can
write sequential code as a bunch of nested function calls that
the compiler optimizes away.  Haskell has syntactic support
for this, so the code you'd write looks somewhat C-like:

  do {
     b <- f a;
     c <- g b;
     d <- h c

but it is actually even cooler than that (complicated to explain so I
won't try here).  The result is that you really insist, you can code
an imperative quicksort that looks about the same as the C one and
compiles to about the same machine code, but is fully typesafe and

More information about the Python-list mailing list