inits

Nils Anders Danielsson nad at cs.chalmers.se
Sat Apr 8 12:50:00 EDT 2006


On Fri, 07 Apr 2006, "Spencer Janssen" <spencerjanssen at gmail.com> wrote:

>> inits xs = [] : (zipWith take [1..] $ map (const xs) xs)

> As this version performs much better and will work as a drop in
> replacement, I suggest that it be included in the hierarchical
> libraries.

It is not a drop in replacement. The original inits is strict, this
one isn't.

The specification of inits (from the Haskell 98 report):

  inits                   :: [a] -> [[a]]
  inits []                =  [[]]
  inits (x:xs)            =  [[]] ++ map (x:) (inits xs)

-- 
/NAD



More information about the Libraries mailing list