
Hi, Consider such a case: I'm making a client program. There is a process, client and server exchange some information in a strict order. So I do (persudo code): exchange = do sendHello readMsg >>= expect hello processHelloReply sendWhatsyourname readMsg >>= expect name processNameReply And expect is something like: expect c f (cmd, msg) = if c == cmd then f msg else fail "unexpected" This is OK until this situation: The server may send some special command, for example DEBUG, DISCONNECT. This breaks the process above. So I think I could throw the unexpected command to outer function to handle. Something like: main = do connect catch exchange $ \e -> do case e of UnexpectedCMD DEBUG -> -- ignore process UnexpectedCMD DISCONNECT -> -- disconnect process _ -> -- something really wrong Well, with Control.Exception, I do not know how to make this done. And with something like Data.Either, I got more problem like: 36| Couldn't match expected type `Control.Monad.Trans.State.Lazy.StateT 37| InternalState IO b' 38| with actual type `Either (Int8, ByteString) b1' 39| Expected type: (Int8, ByteString) 40| -> Control.Monad.Trans.State.Lazy.StateT InternalState IO b 41| Actual type: (Int8, ByteString) -> Either (Int8, ByteString) b1 -- 竹密岂妨流水过 山高哪阻野云飞

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 1/26/11 21:10 , Magicloud Magiclouds wrote:
Hi, Consider such a case: I'm making a client program. There is a process, client and server exchange some information in a strict order. So I do (persudo code): exchange = do sendHello readMsg >>= expect hello processHelloReply sendWhatsyourname readMsg >>= expect name processNameReply
And expect is something like: expect c f (cmd, msg) = if c == cmd then f msg else fail "unexpected"
This is OK until this situation: The server may send some special command, for example DEBUG, DISCONNECT. This breaks the process above. So I think I could throw the unexpected command to outer function to handle. Something like: main = do connect catch exchange $ \e -> do case e of UnexpectedCMD DEBUG -> -- ignore process UnexpectedCMD DISCONNECT -> -- disconnect process _ -> -- something really wrong
Well, with Control.Exception, I do not know how to make this done.
It looks to me like the very example in the Control.Exception documentation will do this, with some renaming.
-- many languages call this a "control exception"; think break/next -- etc. It's an exception used internally to modify control flow. data ControlException = CEDebug | CEDisconnect deriving (Show, Typeable)
instance Exception ControlException
So now you can trap your ControlException above, or anything else is presumably a true exception. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1A3RgACgkQIn7hlCsL25XRMgCeNEImC8VWPiM0fHB5Bu2ooFc8 nz8An0TwHXXUxJl7bhndSVf2vxWbXpGf =HIqR -----END PGP SIGNATURE-----

On Thu, Jan 27, 2011 at 10:48 AM, Brandon S Allbery KF8NH
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 1/26/11 21:10 , Magicloud Magiclouds wrote:
Hi, Consider such a case: I'm making a client program. There is a process, client and server exchange some information in a strict order. So I do (persudo code): exchange = do sendHello readMsg >>= expect hello processHelloReply sendWhatsyourname readMsg >>= expect name processNameReply
And expect is something like: expect c f (cmd, msg) = if c == cmd then f msg else fail "unexpected"
This is OK until this situation: The server may send some special command, for example DEBUG, DISCONNECT. This breaks the process above. So I think I could throw the unexpected command to outer function to handle. Something like: main = do connect catch exchange $ \e -> do case e of UnexpectedCMD DEBUG -> -- ignore process UnexpectedCMD DISCONNECT -> -- disconnect process _ -> -- something really wrong
Well, with Control.Exception, I do not know how to make this done.
It looks to me like the very example in the Control.Exception documentation will do this, with some renaming.
-- many languages call this a "control exception"; think break/next -- etc. It's an exception used internally to modify control flow. data ControlException = CEDebug | CEDisconnect deriving (Show, Typeable)
instance Exception ControlException
So now you can trap your ControlException above, or anything else is presumably a true exception.
- -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk1A3RgACgkQIn7hlCsL25XRMgCeNEImC8VWPiM0fHB5Bu2ooFc8 nz8An0TwHXXUxJl7bhndSVf2vxWbXpGf =HIqR -----END PGP SIGNATURE-----
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
This is one way. But so the outer function could not know what happened in "really wrong" situation. -- 竹密岂妨流水过 山高哪阻野云飞

On Thu, Jan 27, 2011 at 11:00 AM, Magicloud Magiclouds
On Thu, Jan 27, 2011 at 10:48 AM, Brandon S Allbery KF8NH
wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 1/26/11 21:10 , Magicloud Magiclouds wrote:
Hi, Consider such a case: I'm making a client program. There is a process, client and server exchange some information in a strict order. So I do (persudo code): exchange = do sendHello readMsg >>= expect hello processHelloReply sendWhatsyourname readMsg >>= expect name processNameReply
And expect is something like: expect c f (cmd, msg) = if c == cmd then f msg else fail "unexpected"
This is OK until this situation: The server may send some special command, for example DEBUG, DISCONNECT. This breaks the process above. So I think I could throw the unexpected command to outer function to handle. Something like: main = do connect catch exchange $ \e -> do case e of UnexpectedCMD DEBUG -> -- ignore process UnexpectedCMD DISCONNECT -> -- disconnect process _ -> -- something really wrong
Well, with Control.Exception, I do not know how to make this done.
It looks to me like the very example in the Control.Exception documentation will do this, with some renaming.
-- many languages call this a "control exception"; think break/next -- etc. It's an exception used internally to modify control flow. data ControlException = CEDebug | CEDisconnect deriving (Show, Typeable)
instance Exception ControlException
So now you can trap your ControlException above, or anything else is presumably a true exception.
- -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk1A3RgACgkQIn7hlCsL25XRMgCeNEImC8VWPiM0fHB5Bu2ooFc8 nz8An0TwHXXUxJl7bhndSVf2vxWbXpGf =HIqR -----END PGP SIGNATURE-----
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
This is one way. But so the outer function could not know what happened in "really wrong" situation.
-- 竹密岂妨流水过 山高哪阻野云飞
Sorry, in last mail, I meant, in really wrong situation, there might be other tens of unexpected command, I'd like to wrap them in one exception, other than making tens of exceptions. -- 竹密岂妨流水过 山高哪阻野云飞

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 1/26/11 22:02 , Magicloud Magiclouds wrote:
Sorry, in last mail, I meant, in really wrong situation, there might be other tens of unexpected command, I'd like to wrap them in one exception, other than making tens of exceptions.
I'm not sure you can get away with that in a monadic computation, unless you hold all the exceptions until everything is done... and if there's no way to control "everything is done" you have a potential DoS. (Worse, it looked to me like one of those ControlExceptiion-s *was* the "everything is done", which makes holding onto things problematic plus makes me wonder what good the debug message is if it's batched until protocol shutdown. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1A4e0ACgkQIn7hlCsL25X8lQCbBrKO5Lmwazn9025FcDlZ8DYH 2BEAoKuc6bVOH3gG13aa9OUkBoCCmLiP =0NWM -----END PGP SIGNATURE-----

On Thu, Jan 27, 2011 at 11:09 AM, Brandon S Allbery KF8NH
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 1/26/11 22:02 , Magicloud Magiclouds wrote:
Sorry, in last mail, I meant, in really wrong situation, there might be other tens of unexpected command, I'd like to wrap them in one exception, other than making tens of exceptions.
I'm not sure you can get away with that in a monadic computation, unless you hold all the exceptions until everything is done... and if there's no way to control "everything is done" you have a potential DoS. (Worse, it looked to me like one of those ControlExceptiion-s *was* the "everything is done", which makes holding onto things problematic plus makes me wonder what good the debug message is if it's batched until protocol shutdown.
- -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk1A4e0ACgkQIn7hlCsL25X8lQCbBrKO5Lmwazn9025FcDlZ8DYH 2BEAoKuc6bVOH3gG13aa9OUkBoCCmLiP =0NWM -----END PGP SIGNATURE-----
Yes, the problem is that Exception cannot hold anything in it. Things like Either might work. I am thinking how to make it work with StateT.... -- 竹密岂妨流水过 山高哪阻野云飞

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 1/26/11 22:13 , Magicloud Magiclouds wrote:
Yes, the problem is that Exception cannot hold anything in it. Things like Either might work. I am thinking how to make it work with StateT....
That wasn't my point, but sure it can. Go take a look at the IO exception, and in particular (ioeGetErrorType). (http://www.haskell.org/ghc/docs/latest/html/libraries/base-4.3.0.0/System-IO...) - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1A5HEACgkQIn7hlCsL25WajQCgnFlH0/k6W9I5qBvJSvrqSN0q bXoAn1yFY5eh9lvxcpv4VTEpZSasOKoW =3JhM -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 1/26/11 22:00 , Magicloud Magiclouds wrote:
This is one way. But so the outer function could not know what happened in "really wrong" situation.
How so? (1) fromException lets you test it: if (fromException e :: Maybe ControlException) returns a (Just ce), then you have a ControlException. (2) see under (catches) for examples of how to catch specific exception types. If you don't catch anything but ControlException then the exception propagates upward unchanged, which is exactly what you want. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk1A4S8ACgkQIn7hlCsL25VKgwCdF0rEO7FI2EFA7kQf2dEC70Oc mdIAnRz69xJCGzdNoDzSFn/NFic+rL5t =2qNi -----END PGP SIGNATURE-----
participants (2)
-
Brandon S Allbery KF8NH
-
Magicloud Magiclouds