[Haskell-cafe] Yet another monad transformer or silly usage of Either?

Eugeny N Dzhurinsky bofh at redwerk.com
Sun Jul 25 11:38:47 EDT 2010

Hello, everybody!

I am trying to develop some sort of library, which supposed to sign into a WEB
service, then perform some requests with it.

Initially I designed methods in the following way

data DServError = InvalidCredentials | InvalidRequest | ...

newtype Result a = Result { getOpResult :: Either DServError a }

data DSession = Session { ... }

data DLoginResponse = LoginResponse { currentSession :: DSession, ... }

login :: String -> String -> IO ( Result LoginResponse )

servRequest1 :: DSession -> ParamType1 -> ParamType2 -> ... -> IO ( Result DServResponse )

Now I want to be able of doing something like

authenticatedReq = do
    loginResponse <- login "username" "password"
    let session = currentSession loginResponse
    servRequest1 session ... ... ...
    servRequest2 session ... ... ...

so if login succeeds - I will be able to extract Right data from the Either response ( with 
explicit or implicit usage of getOpResult), if any of operations within "do"
block will fail with DServError - then an error should be reported.

I think the solution for this may be using Control.Exception and it's
try/catch? Or may be there's some trick available for Either?

I looked at EitherT, and it seems that I have to wrap every invocation into
EitherT and then chain them with >>/>>=

Eugene Dzhurinsky
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100725/cf733c33/attachment.bin

More information about the Haskell-Cafe mailing list