Monad Conversion

Let's say I have a function

(>>*=) :: (Show e') => Either e' a -> (a -> Either e b) -> Either e b

which converts errors of various types into pure ordered functions. I am very pleased with this.

BUT

Could there be a function <*-that would perform a similar task with a keyword <-that doesn't look too alarming?

+3
source share
2 answers

It is impossible to write a function that you can use instead of <-in a notation. The reason is that <-there is a template to the left of it, but functions take values. But maybe you can write a function

foo :: (Show e') => Either e' a -> Either e a

which converts error messages and then uses them as follows:

do  x <- foo $ code that creates e1 errors
    y <- foo $ code that creates e2 errors

, <*-, , .

+3

, , Toxaris foo :: Either e a -> Either e' a, .

foo - , monad morphism: . , ( ) "" . ( "" - , , ...)

, >>*= Haskell. >>*= , :

(>>*=) :: Monad m => n a -> (a -> m b) -> m b
na >>*= k = morph na >>= k
    where 
      -- Must be a monad morphism:
      morph :: n a -> m a
      morph = ...

>>*= >>= . mmorph, , "" - , morph :: Error e a -> Error e' a StateT s (ErrorT e IO) a StateT s (ErrorT e' IO) a.

+5

All Articles