[clean-list] Clean in the Real World
Marco Kesseler
m.wittebrood@mailbox.kun.nl
Wed, 07 Jan 2004 19:35:50 +0100
On Mon, 2004-01-05 at 17:20, Tomasz Zielonka wrote:
> On Mon, Jan 05, 2004 at 04:51:42PM +0100, Ronny Wichers Schreur wrote:
> >
> > >After some getting used to it, Monads are a pleasure to work with.
> > >If there is anything in Haskell that gets in my way, it ain't Monads.
> >
> > I don't think that Marco's objection is that monads are difficult to
> > use, but rather that their inappropriate use can lead to inelegant
> > programs.
>
> On the other hand, they can lead to very elegant programs. IO is not the
> only monad. You can write purely functional code using monads. They can
> reduce the complexity of code - for example take monadic parser
> combinators.
>
> I know you can design a non-monadic parser combinator library, but
> monadic parsers are really nice when you have syntactic sugar for them.
> What's more, there are many useful functions working with monads in
> general and you can use many design patterns with all monads.
Yes, I think that inelegant programs should be banned!! I believe they
already sent a few to Mars... (the last one sends nice pictures though).
Seriously now: You are right Ronny: I do not find monads "difficult" to
use, in principle, assuming that one one planned to use them from the
start... The "inelegance" issue needs some refinement. Irrespective of
elegance, I am not fundamentally against using monads as a technique. I
am against using monads as a fundamental solution.
Erik already pointed out that monads are not essential for parsing in
general. You can write perfectly elegant, well-designed, parsers without
them. Similarly, I am not convinced that they are essential exception
handling either.
Would an elegant monadic Haskell program be just as elegant in say C?
And how about C++, or Java? or Erlang, Eiffel, SmallTalk, OCaml or...
Lisp? If I am to do _impure_ functional programming anyway, wouldn't it
be better to use the full power of one of these languages, than be
dealing with some "do" notation? For the impure parts, that is. You
actually _can_ program elegantly in these other languages too (note that
I did _not_ mention Cobol).
And, as libraries and useful functions were mentioned: take a look at
sourceforge.net. I'd rather just take some of it and extend it with some
purely functional code, than that I have to redevelop the whole lot
using monads.
So, it is not just about elegance. There is also a practical component.
> > Same for uniqueness typing.
>
> Same for all programming language features.
No. Most features in a functional programming language do _not_ force
you into an imperative style of programming. Uniqueness typing and
monads restrict the way in which expressions can be used.
Ever tried to convert a truly elegant functional program without any IO
into one that writes "ouch!" to a file somewhere "deep inside" its
computation?
Same problem if you want to catch an exception there.
One of the points I am trying to make is that software developers hardly
ever develop a whole new program from scratch. There is always _some_
existing code base. If there isn't, look again.
regards,
Marco