[Haskell-beginners] Understanding program stack usage

Patrick LeBoutillier patrick.leboutillier at gmail.com
Wed Apr 27 22:25:46 CEST 2011


Daniel,

On Wed, Apr 27, 2011 at 2:41 PM, Daniel Fischer
<daniel.is.fischer at googlemail.com> wrote:

> I'm not sure that alone would help. I think he'll still get a thunk
> (M.alter f slot (M.alter f slot (... ())).
>
> record would need to force the Map, easiest to make Distrib strict in the
> map,
>
> data Distrib n = Distrib !(M.Map (Range n Int)) [Range n]
>
> Another point is that he uses a foldr, which generally is a bad strategy
> for building Maps, much better to use foldl' in general.

The bang and the foldl' made it super fast (1 sec) and extra stack is
no longer required.
After searching a bit on my own I had a feeling that the problem has
with the call to M.alter,
but I didn't know how to force the evaluation.

For me this is the biggest problem with using Haskell on a day-to-day
basis for work stuff (which I usually
do in Perl or even BASH). It takes me longer to write the program and
it (sometimes) takes longer for the program to run.

I suppose with practice I'll get better...

Thanks for the tips,


Patrick




-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada



More information about the Beginners mailing list