如何 运行 `ExceptT e m a` do 块中的 `m (Either e a)` 动作?

How to run `m (Either e a)` actions in an `ExceptT e m a` do block?

第一次(有点)试用变形金刚,我正在尝试使用以下功能:

getEnvList :: Text -> IO (Either String [Text])

的 do 块中
type EitherIO a = ExceptT String IO a
script :: EitherIO ()

我想我应该可以做到:

entryKeys :: [Text] <- pure $ getEnvList active_cac_entries

但是,我得到这个错误:

    • Couldn't match expected type ‘IO (Either String [Text])’
                  with actual type ‘[Text]’
    • When checking that the pattern signature: [Text]
        fits the type of its context: IO (Either String [Text])
      In the pattern: entryKeys :: [Text]
      In a stmt of a 'do' block:
        entryKeys :: [Text] <- pure $ getEnvList active_cac_entries
   |
93 |   entryKeys :: [Text] <- pure $ getEnvList active_cac_entries
   |   ^^^^^^^^^^^^^^^^^^^

这种情况的正确函数是 ExceptT 构造函数:

ExceptT :: m (Either e a) -> ExceptT e m a

-- do ...
--    entry <- ExceptT $ getEnvList active_cac_entries
--    ...