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
pgpP8eCkSjmYB.pgp
Description: PGP signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
