1. new in this version
  2. build a web 2.0 app in happstack
  3. why happstack is cool
  4. getting started with happstack
  5. prerequisites
  6. cabal install me
  7. first shot at happstack
  8. url handling
  9. basic HTML inclusion
  10. templates
  11. stringtemplate basics
  12. debugging
  13. form data: get and post
  14. form data: file uploads
  15. cookies
  16. introduction to macid
  17. first steps with macid
  18. scaling with multimaster
  19. using macid safely
  20. macid dummy data
  21. changing the data model
  22. macid stress test
  23. limitations of macid
  24. foreign characters
  25. IxSets
  26. cron jobs
  27. thanks
  28. appendix (floundering in ghci)

Your first applications with Happstack.State

Now we're getting into the very basics of how to make an application with Happstack.State.

Take a look at the application defined in FirstMacid.hs, read the comments, and copy it somewhere you feel comfortable running it.

Play with it at the command prompt for a bit. Choose various values to add to the state. Close the program, and then reload it. Check the state and everything should be saved right where you left it. Cool, eh?

One thing I want to point out is that this example makes no use of Happstack.Server whatsoever. They are completely independent of each other.

Now here's a second example to look at, one that demonstrates using a non-trivial Dependencies list in order to improve modularity: ComponentExample.hs. Again, you'll want to read the inline comments as they contain the bulk of the instruction of this chapter.

To summarize the major points of this chapter:

  • By default, Happstack.State serializes an event record under the _local directory.
  • The state management is started with the startSystemState function
  • For a data type to be used as the state, it needs to be an instance of Component which itself requires a number of other instances.
  • Checkpointing allows you to serialize the actual state and not just the event record.
    • You can roll back time by deleting the events that took place after the checkpoint.
    • Checkpointing must be done by manually calling createCheckpoint
  • Dependencies allow separate components to be combined together into the final top level state.

Next we'll talk about creating distributed applications using Happstack.State.