[Haskell-cafe] How can we detect and fix memory leak due to
spencerjanssen at gmail.com
Mon Aug 7 21:14:04 EDT 2006
On 8/7/06, Ahn, Ki Yung <kyagrd at gmail.com> wrote:
> I have posted an wiki article including one example of adding
> a counter to count the number of basic operations in sorting algorithm.
> This was a rather simple situation and we figured out how to
> cure this by self equality check ( x==x ) forcing evaluation.
Forcing evaluation using (==) is a bit of a hack. Luckily, we have a
better function to force evaluation: seq (which has type a -> b -> b).
"seq x y" evaluates "x" to weak head normal form before returning
Let's try another feature of Haskell to force evaluation: strict data
fields. A ! in front of a field in a data declaration signifies
strictness. In the example below, whenever we construct a value with
TT, the second argument is evaluated.
data TT a b = TT a !b
Perhaps your instances will work correctly with this data declaration?
More information about the Haskell-Cafe