-- Unlike Data.List.subsequences, this returns subsequences in increasing length order
subsequences :: [a] -> [[a]]
subsequences xs = concat $ unfoldr f [([], xs)]
  where
    f :: [([a], [a])] -> Maybe ([[a]], [([a], [a])])
    f lasts = if null nexts then Nothing
              else Just (map fst nexts, nexts)
      where nexts = [ (soFar ++ [nxt], rest) | (soFar, remaining) <- lasts, (nxt, rest) <- splits remaining ]
    splits ys = zip ys (drop 1 $ tails ys)
subsequences :: [a] -> [[a]]
subsequences xs = concat $ unfoldr f [([], xs)]
  where
    f :: [([a], [a])] -> Maybe ([[a]], [([a], [a])])
    f lasts = if null nexts then Nothing
              else Just (map fst nexts, nexts)
      where nexts = [ (soFar ++ [nxt], rest) | (soFar, remaining) <- lasts, (nxt, rest) <- splits remaining ]
    splits ys = zip ys (drop 1 $ tails ys)
subsequences xs = concat $ unfoldr f [([], xs)]
  where
    f :: [([a], [a])] -> Maybe ([[a]], [([a], [a])])
    f lasts = if null nexts then Nothing
              else Just (map fst nexts, nexts)
      where nexts = [ (soFar ++ [nxt], rest) | (soFar, remaining) <- lasts, (nxt, rest) <- splits remaining ]
    splits ys = zip ys (drop 1 $ tails ys)