maxsubseq :: (Ord a, Num a) => [a] -> (a, [a]) maxsubseq = snd . foldl f ((0,[]),(0,[])) where f ((maxToHere,witnessToHere),(maxSoFar, witnessSoFar) x = (a,b) where a = max (0,[]) (fst x + maxToHere, x:witnessToHere) b = max sofar a