Functional programming in Python

Kellomaki Pertti pk@cs.tut.fi
Tue, 22 May 2001 17:51:58 +0300


I realize this is a topic where it would be very easy to start a flame
war, but hopefully we can avoid that.

Paul Hudak wrote:
> Why not have your tool generate layout-less code?  Surely that would be
> easier to program, and be less error prone.

The tool in question is Happy, and the error materialized as an
interaction
between the tool-generated parser code and the hand-written code in
actions.
So no, this was not an option since the tool is not written by me, and
given
my current capabilities in Haskell I could not even fix it. On the other
hand 
the bug is easy to work around, and it might even be fixed in newer
versions 
of Happy.
 
> Yes, but the layout is not ENFORCED.  I programmed in Lisp for many
> years before switching to Haskell, and a common error is something like
> this:
> 
> >     (let ((a 0)
> >           (b 1)
> >        (+ a b)))
> 
> In this case the error is relatively easy to spot, but in denser code it
> can be very subtle.  So in fact using layout in Lisp can imply a
> semantics that is simply wrong.

Maybe I did not express my point clearly. What I was trying to say was
that
because of the syntax, it is very easy for M-C-q in Emacs to convert
that to

(let ((a 0)
      (b 1)
      (+ a b)))

which brings the layout of the source code to agreement with how it is
perceived
by the compiler/interpreter. So it is easy for me to enforce the layout.

This is not so much of an issue when you are writing the code in the
first place,
but I find it a pain to have to adjust indentation when I move bits of
code around
in an evolving program. If there is good support for that, then I'll
just shut up
an start using it. After all, I have only been using Haskell for a very
short
period of time.
-- 
pertti