import Data.List
-- greedy algorithm
next :: Integral a => a ->[a] -> [a]
next c ms = bs ++ 1: genericReplicate n 
where (as, bs) = genericSplitAt c ms
n = c - sum as
sequences :: Integral a => a -> a -> [[a]]
sequences c n | c > n     = []
| otherwise = iterate (next c) $ genericReplicate n 
-- Test functions
test m c n = mapM_ print.take m $ sequences c n
loop1 c n = loop $ sequences c n
where loop (x:y:zs) | x == y    = x
| otherwise = loop (y:zs)
testLoop1 c m = mapM_ print.take m.map (loop1 c) $