mapAccumLCM :: (Monad m) => (a -> b -> c) -> (acc -> a -> m (acc, b))
          -> acc -> [a] -> m (acc, [c])
mapAccumLCM g f s l = case l of
  [] -> return (s, [])
  x : xs -> do
    (s', y) <- f s x
    (s'', ys) <- mapAccumLCM g f s' xs
    return (s'', g x y : ys)

{- | Monadic version of concatMap
     taken from http://darcs.haskell.org/ghc/compiler/utils/MonadUtils.hs -}
mapAccumLCM :: (Monad m) => (a -> b -> c) -> (acc -> a -> m (acc, b))
          -> acc -> [a] -> m (acc, [c])
mapAccumLCM g f s l = case l of
  [] -> return (s, [])
  x : xs -> do
    (s', y) <- f s x
    (s'', ys) <- mapAccumLCM g f s' xs
    return (s'', g x y : ys)

{- | Monadic version of concatMap
     taken from http://darcs.haskell.org/ghc/compiler/utils/MonadUtils.hs -}
mapAccumLCM g f s l = case l of
  [] -> return (s, [])
  x : xs -> do
    (s', y) <- f s x
    (s'', ys) <- mapAccumLCM g f s' xs
    return (s'', g x y : ys)

{- | Monadic version of concatMap
     taken from http://darcs.haskell.org/ghc/compiler/utils/MonadUtils.hs -}