将 monad 添加到转换器堆栈的中间
Add a monad to the middle of a transformer stack
我正在尝试 "semilift" (ExceptT Error IO Foo)
到 (ExceptT Error (StateT Bar IO) Baz)
。
我试过 lift
、fmap lift
、fmap return
和 none;这里有标准成语吗?
> 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
忽略 ExceptT
新类型,你有
IO (Either Error Foo)
而你想要
StateT Bar IO (Either Error Foo)
(Baz
我没看到你想要什么,所以我忽略了它。)
也就是 lift
。所以我相信你应该可以使用
ExceptT . lift . runExceptT
作为, this can be written using mapExceptT
:
mapExceptT lift
我正在尝试 "semilift" (ExceptT Error IO Foo)
到 (ExceptT Error (StateT Bar IO) Baz)
。
我试过 lift
、fmap lift
、fmap return
和 none;这里有标准成语吗?
> 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
忽略 ExceptT
新类型,你有
IO (Either Error Foo)
而你想要
StateT Bar IO (Either Error Foo)
(Baz
我没看到你想要什么,所以我忽略了它。)
也就是 lift
。所以我相信你应该可以使用
ExceptT . lift . runExceptT
作为mapExceptT
:
mapExceptT lift