inits is not a direct list fold: inits undefined = [] : undefined has a defined outer constructor, while foldr c z undefined is .Both For
pinits and ninits are direct list folds:pinitsFold :: [a] -> [[a]]
pinitsFold = foldr (\x yss -> [] : map (x:) yss) []
ninitsFold :: [a] -> [[a]]
ninitsFold = foldr (\x yss -> [x] : map (x:) yss) []pinits, the combining function is exactly the recursive step above. For ninits, expand inits xs = [] : ninits xs and useNeither step needs to inspect yss before producing its first outer constructor. Thus the definitions satisfy the fold factorisation criterion on partial as well as total lazy lists. Articles by others on the same topic
There are currently no matching articles.