On Mon, 2007-29-01 at 20:14 +0100, Michael Roth wrote:
Ok, the tool written in Haskell works. But, to me, the source doesn't
look very nice and even it is larger than the ruby solution, and more
imporant, the programm flow feels (at least to me) not very clear.

I am by no means a Haskell (or even FP) expert so I'll let the experts talk about your code and will instead focus on philosophy.

I think that whole "program flow" thing is something you get used to.  In true, pure functional programming (i.e. Haskell) "program flow" is a meaningless term, basically.  Haskell is a declarative language, not an imperative one.  You have to learn to give up that control and trust the runtime to Do The Right Thing.  (In this regard it's similar to logic programming languages.)

My canonical example is the three-line quicksort:

quicksort :: Ord a => [a] -> [a]
quicksort []     = []
quicksort (x:xs) = quicksort [y|y<-xs,y<x] ++ [x] ++ quicksort [y|y<-xs,y>=x]

(I hope I have that down right.)

The flow through that code is highly inobvious.  You are defining, in effect, a computation, not how the computation is being done.  It's up to the runtime to figure out which version of the function gets run and when.

Now, of course, there are tools in place to permit you to control program flow if you need to.  (The omnipresent Monads.)  But the key here is that you should be sure you need this before you use it.  It's hard -- very hard (I've not yet succeeded) -- to give up that control when you come from an imperative background.

-- 
Michael T. Richter
Email: ttmrichter@gmail.com, mtr1966@hotpop.com
MSN: ttmrichter@hotmail.com, mtr1966@hotmail.com; YIM: michael_richter_1966; AIM: YanJiahua1966; ICQ: 241960658; Jabber: mtr1966@jabber.cn

"Sexual organs were created for reproduction between the male element and the female element -- and everything that deviates from that is not acceptable from a Buddhist point of view. Between a man and man, a woman and another woman, in the mouth, the anus, or even using a hand." --The Dalai Lama