[Haskell-cafe] Problem about exception

oleg at okmij.org oleg at okmij.org
Thu Jan 27 10:05:01 CET 2011


It seems that the problem is to follow a protocol, reporting protocol
errors (unexpected responses) and permitting recovery if the
`supervisor' decided that the error can be fixed by re-reading from
the server.

This problem -- specifically, communicating with a supervisor
`out-of-band' and recovery -- is a good use case for delimited
continuations.

The following code implements the scenario in Magicloud's
message. 
   http://okmij.org/ftp/continuations/CCmonad/ProtocolRecovery.hs

Actually, the code is interactive, letting the use play a
good or a bad server. One can see for themselves the effect of
expected or unexpected responses. The title comments show the examples
of good or bad interactions. Here is a sample transcript of several
interactions.



ProtocolRecovery> main
Client Connected
sending: Req_hello
Enter response, as a number 1..4
1
sending: Req_who_are_you
Enter response, as a number 1..4
2
Client Dis-connected

ProtocolRecovery> main
Client Connected
sending: Req_hello
Enter response, as a number 1..4
1
sending: Req_who_are_you
Enter response, as a number 1..4
3
Exception: Err_bad_resp Res_debug
DEBUG
Enter response, as a number 1..4
3
Exception: Err_bad_resp Res_debug
DEBUG
Enter response, as a number 1..4
2
Client Dis-connected

*ProtocolRecovery> main
Client Connected
sending: Req_hello
Enter response, as a number 1..4
1
sending: Req_who_are_you
Enter response, as a number 1..4
4
Exception: Err_bad_resp Res_disconnect
Aborting
Client Dis-connected

*ProtocolRecovery> main
Client Connected
sending: Req_hello
Enter response, as a number 1..4
1
sending: Req_who_are_you
Enter response, as a number 1..4
1
Exception: Err_bad_resp Res_hello
Really bad response!
Client Dis-connected



More information about the Haskell-Cafe mailing list