如何从Shell monad中提取值?
我想像bash的&&
一样排序一个命令列表,但我也想提取最终的ExitCode
值。
假设我有以下代码:
import Turtle
type Commands = [Shell ExitCode]
run :: (MonadIO io) => Commands -> io ExitCode
run cs = whatIsThisFunction $ Prelude.foldl (.&&.) (return ExitSuccess) cs
whatIsThisFunction :: (MonadIO io) => Shell a -> io a
whatIsThisFunction = undefined
我试图使用Control.Foldl实现这个功能,但没有找到解决方案。
有什么想法吗?
更普遍地说,为什么Turtle不提供一个具有这样签名的函数:
sh' :: MonadIO io => Shell a -> io a
Tt.sh cmds `catches` [ Handler (\(e::Tt.ProcFailed) -> Log.error $ show e) , Handler (\(e::Tt.ShellFailed) -> Log.error $ show e) , -- etc. ]
你同意吗?(抱歉代码格式不好,我不知道如何在评论中处理) - damien.courousse