
Thomas Hartman
In the latest happs (darcs pulled, updated head is 0.9.1 iirc), I am experimenting with the example file in
src/HAppS/Examples/HTTP1.hs.
I would like to combine state with io. Eventually io will mean stuff like reading from a database, but for now I'm just reading a file. The example file HTTP1.hs has an example that demonstrates state with macid. I added an example that allows you to execute arbitrary io. I tried, but was unable to, add a handler that combines state and io.
, h ["iohandler"] GET $ ioReadFileHandler
, h ["statehandler"] GET $ stateHandler
--, h ["ioandstatehandler"] GET $ ioAndStateHandler ..... -- displays contents of HAPPS.hs in current directory ioReadFileHandler = iohandler $ readFile "./HAppS.hs" -- displays incremented state counter stateHandler = ok $ \() () ->
modify (+(1::Int)) >> get >>= respond . show -- should combine effect of iohandler with statehandler -- specifically, should display contents of HAppS.hs, and under that an incremented state handler -- is this possible ioAndStateHandler = undefined undefined Is mixing state and io possible with HAppS? If so, an example showing how to do it would be extremely helpful. best, thomas. ---This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Attachment (https1-whatsnew): application/octet-stream, 1933 bytes Attachment (HTTP1.hs): application/octet-stream, 4794 bytes
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
I had no trouble getting this handler to work: h ["iohandler"] GET $ \() () -> do modify (+1) x <- get respond $ do cnts <- readFile "./sometext.txt" sresult 200 (cnts ++ show x) I believe the trick is that you cant mix io INTO the HAppS ServerPart monad. But from the ServerPart monad you can RETURN an io action.