[Haskell-cafe] a minor bug (memory leak) in ListLike package

John Lato jwlato at gmail.com
Thu Aug 25 02:25:04 CEST 2011

Thanks for reporting this.  I understand the problem, however I don't
want to bloat the interface even more with a bunch of strict versions
of functions.  Even so, the current implementation is definitely the
worst possible option as it has the slow performance of building
thunks without the actual benefits of laziness.

`Data.List` currently uses a fully lazy implementation, with RULEs to
specialize to a strict variant for Int and Integer accumulators.  The
same solution should work for ListLike, with the following additions:

1.  `length` be made fully strict in the accumulator
2.  `genericLength'` (strict variant) be exposed via the interface

Currently I know of no way to automatically derive listlike-instances,
however the `listlike-instances` package has instances for a few other
useful types (vectors and Text mainly).  Adding instances is
definitely a pain, so I may well try to create a Derive extension for
the next time I want to do so.


On Wed, Aug 24, 2011 at 5:17 AM, bob zhang <bobzhang1988 at gmail.com> wrote:
> 于 11-8-23 下午11:37, Ivan Lazar Miljenovic 写道:
>> It might not be what_you_  want, but it might be what others want.  If
>> you're concerned with efficiency, then wouldn't you use length rather
>> than genericLength?
> length is identical to genericLength in ListLike except type signature.
> but still,
> import Data.Number
> import Data.List
> import qualified Data.ListLike as L
> (3 :: Natural) < genericLength [1..] (work)
> (3 :: Natural) < L.genericLength [1..] (non-terminating)
> If you want laziness, L.genericLength should be defined like this
> L.genericLength [] = 0
> L.genericLength (_:l) = 1 + L.genericLength l
> the genericLength used in ListLike package used tail recursion while
> non-strict.
> and also, a strict length is still needed (currently, length is identical to
> genericLength)
> Thank you
> bob

More information about the Haskell-Cafe mailing list