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

bob zhang bobzhang1988 at gmail.com
Wed Aug 24 06:17:59 CEST 2011


于 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