История изменений
Исправление qnikst, (текущая версия) :
import Control.Monad.Trans.Either
import "mtl" Control.Monad.State
import Data.DList (DList)
import qualified Data.DList as DL
data Q = Q Int deriving Show
type M a b = EitherT a (State (DList Q)) b
l :: Q -> M a ()
l y = lift $ modify (\x -> x `DL.snoc` y)
e :: a -> M a ()
e x = left x
test1 = do
l (Q 1)
l (Q 2)
e ()
l (Q 3)
λ> fst $ runState (runEitherT test1) DL.empty
Left ()
λ> DL.toList . snd $ runState (runEitherT test1) DL.empty
[Q 1,Q 2]
хотя я бы делал по другому..
Исходная версия qnikst, :
import Control.Monad.Trans.Either
import "mtl" Control.Monad.State
import Data.DList (DList)
import qualified Data.DList as DL
data Q = Q Int deriving Show
type M a b = EitherT a (State (DList Q)) b
l :: Q -> M a ()
l y = lift $ modify (\x -> x `DL.snoc` y)
e :: a -> M a ()
e x = left x
test1 = do
l (Q 1)
l (Q 2)
e ()
l (Q 3)
λ> fst $ runState (runEitherT test1) DL.empty
λ> DL.toList . snd $ runState (runEitherT test1) DL.empty
[Q 1,Q 2]
хотя я бы делал по другому..