代码之家  ›  专栏  ›  技术社区  ›  Nathan Ringo

将单子添加到transformer堆栈的中间

  •  2
  • Nathan Ringo  · 技术社区  · 7 年前

    我试着“半提”一个 (ExceptT Error IO Foo) (ExceptT Error (StateT Bar IO) Baz) .

    我试过了 lift fmap lift fmap 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
    
    1 回复  |  直到 7 年前
        1
  •  5
  •   dfeuer    7 年前

    忽略 ExceptT 新类型,你有

    IO (Either Error Foo)
    

    而你想要

    StateT Bar IO (Either Error Foo)
    

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

    lift

    ExceptT . lift . runExceptT
    

    Alec noted mapExceptT :

    mapExceptT lift