在 Haskell 中执行多个命令的基本问题

Basic question on executing multiple commands in Haskell

我的代码如下:

  where
    launch :: MonadIO m => m (Maybe Text)
    launch = do
        line <- launchLine
        return $ lineToText <$> line

    launchLine :: MonadIO m => m (Maybe Line)
    launchLine = fold (inproc "juke" ["launch", "--profile", "jukeplay", pack baseImage] mempty) $
        Fold selectLaunchName Nothing id

以上几行工作正常。我的问题(和问题)是我想在此启动行之前执行另一个命令,因此它可能类似于:

  where
    launch :: MonadIO m => m (Maybe Text)
    launch = do
        line <- launchLine
        return $ lineToText <$> line

    launchLine :: MonadIO m => m (Maybe Line)
    launchLine = fold (inproc "juke" ["image", "copy", "jukebox:" <> pack baseImage, "local:", "--copy-aliases"] mempty) $
        Fold selectLaunchName Nothing id

    launchLine :: MonadIO m => m (Maybe Line)
    launchLine = fold (inproc "juke" ["launch", "--profile", "jukeplay", pack baseImage] mempty) $
        Fold selectLaunchName Nothing id

这显然行不通。我怎样才能做到这一点?

我需要在执行 "juke launch.." 之前完成此 "juke image copy"

在此先感谢您的帮助

您可以将 monadic 动作与 (>>):

组合
(>>) :: Monad m => m a -> m b -> m b

或使用 do 语法,脱糖为 (>>):

\act1 act2 -> do {act1; act2} :: Monad m => m a -> m b -> m b

例如:

launch :: MonadIO m => m (Maybe Text)
launch = do
    preLaunchLine
    line <- launchLine
    return $ lineToText <$> line

preLaunchLine :: MonadIO m => m (Maybe Line)
preLaunchLine = fold (inproc "juke" ["image", "copy", "jukebox:" <> pack baseImage, "local:", "--copy-aliases"] mempty) $
    Fold selectLaunchName Nothing id

launchLine :: MonadIO m => m (Maybe Line)
launchLine = fold (inproc "juke" ["launch", "--profile", "jukeplay", pack baseImage] mempty) $
    Fold selectLaunchName Nothing id