inits is too strict
Donald Bruce Stewart
dons at cse.unsw.edu.au
Wed Jun 13 05:59:58 EDT 2007
apfelmus:
> Hello,
>
> inits [] = [[]]
> inits (x:xs) = [[]] ++ map (x:) (inits xs)
>
> as specified in Data.List has a "semantic bug", namely it's too strict:
>
> inits (1:_|_) = []:_|_
>
> as opposed to the expected
>
> inits (1:_|_) = []:[1]:_|_
>
> A correct version would be
>
> inits xs = []:case xs of
> [] -> []
> (x:xs) -> map (x:) (inits xs)
>
> The Haskell report specifies how inits has to behave, so this is a
> problem in the report, not in a concrete implementation. Where can I
> report a bug report for the report? ;)
>
> Regards,
> apfelmus
Well, right here. There are other strictness issues either differing
from the spec, or not clearly defined (foldl', for example).
A useful tool for checking these is the StrictCheck/ChasingBottoms
library, QuickCheck for partial values, by the way.
-- Don
More information about the Haskell-prime
mailing list