<p dir="ltr">In a comment on trac #9345, nomeata proposed the implementation of Data.List.inits below. He indicates that the performance is very good, and wrote it in this fashion so it could fuse. My concern is that since seq is used in the argument to build, we need to make sure that fusion on the left will be safe. If I did the calculations right, this specifically requires that for all f, cons, nil, and bs, and all a≠_|_, the following "correct" expression</p>

<p dir="ltr">e1 = a `cons`<br>
     foldr cons nil $<br>
       foldr (\b g x -> (let b' = f x b in b' `seq` (b' : g b')))<br>
          (\b -> b `seq` [])<br>
          bs<br>
          a</p>
<p dir="ltr">gives the same result as the fused expression</p>
<p dir="ltr">e2 = a `cons`<br>
     foldr (\b g x -> (let b' = f x b in b' `seq` (b' `cons` g b')))<br>
           (\b -> b `seq` nil)<br>
           bs<br>
           a</p>
<p dir="ltr">I haven't been able to figure out how to prove this or give a counterexample, so far, but I have very little experience with such.</p>
<p dir="ltr">myScanl' :: (b -> a -> b) -> b -> [a] -> [b]<br>
myScanl' f a bs = build $ \c n -><br>
     a `seq` a `c`<br>
     foldr (\b g x -> (let b' = f x b in b' `seq` (b' `c` g b')))<br>
           (\b -> b `seq` n)<br>
           bs<br>
           a</p>
<p dir="ltr"> initsQ2 :: [a] -> [[a]]<br>
 initsQ2 = map toListQ . myScanl' snocQ emptyQ</p>