X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FList.hs;h=bb71da5f06b9b9a4b735841f6ff2d165a39cc5bc;hb=HEAD;hp=061ad42a01ad19d3b7b2f1498b03497946410db4;hpb=41e8fba828acbae1751628af50849f5352b27873;p=ghc-base.git diff --git a/Data/List.hs b/Data/List.hs index 061ad42..bb71da5 100644 --- a/Data/List.hs +++ b/Data/List.hs @@ -744,19 +744,24 @@ groupBy eq (x:xs) = (x:ys) : groupBy eq zs -- -- > inits "abc" == ["","a","ab","abc"] -- +-- Note that 'inits' has the following strictness property: +-- @inits _|_ = [] : _|_@ inits :: [a] -> [[a]] -inits [] = [[]] -inits (x:xs) = [[]] ++ map (x:) (inits xs) +inits xs = [] : case xs of + [] -> [] + x : xs' -> map (x :) (inits xs') -- | The 'tails' function returns all final segments of the argument, -- longest first. For example, -- -- > tails "abc" == ["abc", "bc", "c",""] -- +-- Note that 'tails' has the following strictness property: +-- @tails _|_ = _|_ : _|_@ tails :: [a] -> [[a]] -tails [] = [[]] -tails xxs@(_:xs) = xxs : tails xs - +tails xs = xs : case xs of + [] -> [] + _ : xs' -> tails xs' -- | The 'subsequences' function returns the list of all subsequences of the argument. --