[Haskell-cafe] Stacking monads

Andrew Coppin andrewcoppin at btinternet.com
Fri Oct 3 15:56:47 EDT 2008


Andrew Coppin wrote:
> run_or s0 x y =
>    let
>      either_rset1 = sequence $ run s0 x
>      either_rset2 = sequence $ run s0 y
>      either_rset3 = do rset1 <- either_rset1; rset2 <- either_rset2; 
> return (merge rset1 rset2)
>  in case either_rset3 of
>    Left  e    -> throwError e
>    Right rset -> lift rset

Do you realise, this single snippet of code utilises the ErrorT monad 
[transformer], the ResultSet monad, *and* the Either monad, all in the 
space of a few lines?? That's three monads in one function! o_O

I scare *myself*, I don't know about you guys...



More information about the Haskell-Cafe mailing list