[Haskell-beginners] Lazy vs Strict ponderings...

Heinrich Apfelmus apfelmus at quantentunnel.de
Sun Mar 20 10:37:23 CET 2011


sean at objitsu.com wrote:
>>> 2) Don't worry about memory leaks until they actually appear. If they
>>> do, use a profiling tool to find out what's going on. Most likely, one
>>> of the two things above happened in an interesting way.
> 
> At the risk of sounding stupid in Haskell mode, how would I be aware of 
> this other than obvious messages or seg-faults about memory getting low ?

The usual sign is that GHC is requesting more RAM from the OS than it 
should. For instance, if you expect your program to run in constant 
space, but GHCs memory usage keeps growing by 100 MB every twenty 
seconds, then you have a space leak. You can also run a profile 
preemptively and look at the graph.

   http://book.realworldhaskell.org/read/profiling-and-optimization.html


>> It is likely that, if you develop a medium to large sized application for
>> a customer, memory leaks will appear at the customers site. It will often
>> be very difficult to reproduce the situation and find the leak.
> 
> That scares me enough to not want to use Haskell for serious application 
> development. With 26 years in the trade I have had too many times when a 
> fault cannot be reproduced and despite an 'obvious fault in the source' 
> being fixed and the problem never coming back, without being able to 
> reproduce and thus confirm that you have eliminated the problem, you 
> can't ever relax on a Saturday night! LOL
> 
> I hate the word 'random' when clients describe problems too!

That were the fears that I wanted to address with "don't worry". :D

You see, the thing is this: any kind of error can happen at the 
customer's site, be it memory leaks, dangling pointers, division by zero 
or all the nasty bugs you put in your code. The programming language you 
choose influences both the kind of errors and the frequency of errors. 
Choosing Haskell over an imperative language like C, Pascal or Java 
drastically reduces logic bugs, and hence the total frequency of errors, 
even though you might be slightly worse off on the memory leak side, 
because laziness introduces a complication there. But that is a small 
price to pay for the general reduction in errors.


>> See also "On the reliability of programs",
>> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD03xx/EWD303.html

Dijkstra would be very happy about how close mathematics and Haskell are.



Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com




More information about the Beginners mailing list