= Solution
\b[`tails` is not a direct <list fold>.] Every `foldr c z` is strict in its list argument, but `tails undefined = undefined : undefined` has a defined outer constructor. Applying `null` distinguishes this result from $\bot$.
\b[`ptails` is not a direct <list fold> either.] On a type with distinct values `u` and `v`,
$$
\operatorname{ptails}[u]=[[]]=\operatorname{ptails}[v].
$$
A fold step given the same new head `x` and these equal folded tails must return the same result. However,
$$
\operatorname{ptails}[x,u]=[[u],[]]\ne[[v],[]]=\operatorname{ptails}[x,v].
$$
Thus the tail information needed by the next step does not factor through `ptails`; this violates the <fold factorisation criterion> even on finite total lists.
\b[`ntails` is a direct <list fold>:]
``
ntailsFold :: [a] -> [[a]]
ntailsFold = foldr step []
where
step x yss = (x : original yss) : yss
original [] = []
original (ys:_) = ys
``
When the tail is nonempty, its first nonempty <suffix of a list> is the tail itself; otherwise it is recovered as `[]`. Hence `original (ntailsFold xs) = xs`. The inner case distinction is delayed beneath constructors, so the definition also preserves the required behaviour on partial and infinite <lazy lists>. Building a suffix head does not first demand the whole folded tail.
Back to article page