[Haskell-cafe] space leaks and optimizations
Henning Thielemann
lemming at henning-thielemann.de
Fri Jan 15 10:40:46 EST 2010
Ryan Ingram schrieb:
> Hi Alexei, you have a ton of great points but I wanted to discuss an
> issue with this one.
>
> It's unusual that this is what you want either; since it only reduces
> the state to WHNF. For example, if your state is a string, this only
> evaluates enough to know whether or not the string is empty at each
> step, and you can still get into trouble with code like this:
>
> put ("xxx" ++ some_bad_computation)
>
> which leave bottoms inside of your state which won't show up until later.
>
> Several attempts to solve this problem exist, but the most commonly
> used one is the "rnf" strategy from Control.Parallel.Strategies, which
> uses a typeclass to allow each type to specify how to evaluate itself
> completely.
Now available without parallelism in
http://hackage.haskell.org/packages/archive/deepseq/1.1.0.0/doc/html/Control-DeepSeq.html
I think that one should generally think before using seq, because it is
only strict in the top most constructor. If you know the type you 'seq'
on, then you might use a 'case' on it instead and can precisely control
the depth of the strictness. Otherwise you might use 'rnf'.
I have also some problems with space leaks. Recently I found a space
leak in my code, that was because a finalizer did not run as expected.
Now I'm seeking more information on how to use finalizers correctly ...
More information about the Haskell-Cafe
mailing list