Betr.: [clean-list] Passing commandline arguments to a clean program

karczma karczma@info.unicaen.fr
Wed, 08 Sep 2004 00:17:28 +0200


Sander van den Berg writes: 

> Thanks for all the help. I finished my little test program. Its working 
> fine right now except for the following:

> Whenever I try to generate the Character Frequency table of a large text file, 
> I get either heap full or stack errors, even when I increase the heap-size.

> I attached the program.

> Are there any other things I could improve on the code? 

While I am unable to say whether I can help you here, there is always
some place for improvement. For example 

> increaseElement a [x:xs]
>	| a==fst x	= [(a, (snd x)+1)] ++ increaseElement a xs  // ???????
>	| otherwise	= [x] ++ increaseElement a xs

I thought that 'a' has at most one occurrence in the list no? Why this
recursion? 

And anyway, PLEASE! DECLARE IT AS STRICT!
(Actually make strict out of everything you can...) 

Your quicksort is, sorry to say, rather naive. Well, since the list should
be indexed by Chars, this won't overflow anything, but recklessness is
recklessness... 


> inSet a xs
>	| lookup a xs	= increaseElement a xs
>	| otherwise		= xs ++ [(a,1)]   // ?? santa Madonna!

Please, change the last line into  [(a,1):xs]. Making a quadratic algorithm
out of a visibly linear one is a heavy sin. Here also xs should be strict,
by the way. 


Jerzy Karczmarczuk