在变压器堆栈的中间添加一个单子



我正在尝试将(ExceptT Error IO Foo)"半提升"到(ExceptT Error (StateT Bar IO) Baz)

我试过liftfmap liftfmap return,都没有用;这里有标准的成语吗?

> import Control.Monad.Except
> import Control.Monad.State
> data Error
> data Foo
> data Bar
> data Baz
> x = undefined :: ExceptT Error IO Foo
> y = undefined :: (ExceptT Error (StateT Bar IO) Baz) -> a
> f = ??? -- This is what I'm trying to find.
> :t y (f x)
y (f x) :: a

忽略ExceptTnewtypes,你有

IO (Either Error Foo)

你想要

StateT Bar IO (Either Error Foo)

(我看不到你想要什么Baz,所以我忽略了它。

那只是lift.所以我相信你应该能够使用

ExceptT . lift . runExceptT

正如亚历克所指出的,这可以使用mapExceptT来编写:

mapExceptT lift

相关内容

最新更新