Hello,
I am trying to move a web application I wrote that initially used raw sockets for doing HTTP by "hand" to a more sensible Wai-based framework, and I am running into a design issue.
I initially thought it would be a good idea to be able to support various I/O methods so I defined a layer called CommandIO (this is a game application) to insulate business-level code from the detials of reading commands and outputting results to the outside world. Here is the signature for this simple monad:
class (Monad io) => CommandIO io where
readCommand :: io Command
writeResult :: CommandResult -> io ()
then I have an interpret function which looks like:
interpret :: (CommandIO io, Map t) => Commands t io CommandResult
which reads a command from the io, execute it producing a CommandResult, then request output from the io using writeResult.
This works nicely using Reader-based data containing a Handle, both for HTTP-based and console-based I/O.
But when I try to move to WAI, I am a little bit stuck. The core of Wai is an application which rougly has type Request -> Response and this basically breaks my (simple) model of read commands / write results. I suspect there might be a way to stick to my current model using enumerators/streams for I/O and a custom type for encapsulating the underlying state of the HTTP exchange. I also thought about reversing the dependency : ensuring that interpret does not need to know about low-level I/O and only dealing with Command/CommandResult, with I/O being handled by wrappers.
Thanks in advance for any insights,
Arnaud
PS: the code is on github: http://github.com/abailly/crete1941. Not that I deem it ready for prime-time though...