[Haskell-cafe] More idiomatic use of strictness
dons at galois.com
Thu Jul 10 14:03:51 EDT 2008
> On Thu, 2008-07-10 at 03:16 -0700, Grzegorz Chrupala wrote:
> > Hi all,
> > Is there a less ugly way of avoiding laziness in the code pasted below then
> > the use of seq in the last line?
> > The program is supposed to split a large input file into chunks and check in
> > how many of those chunks each of a list of words appear, as well as the
> > total number of chunks. Without the seq it consumes huge amounts of memory.
> Strategies! Try
> ((,) $| rnf) dfs' (n + 1)
> (id $| seqPair rnf r0) (dfs', n + 1)
> But I don't know if that falls within the intended meaning of `less
I'd use a strict pair and the rnf strategy.
data P = P [Something] !Int
rnf dfs' (P dfs' (n+1)
More information about the Haskell-Cafe