Storyboard Player

From UBC Wiki

What is the problem?

Text based adventure games are a lot of fun, and functional programming in Haskell provides an intuitive way to create interactive games using tree or graph-like data structures (like the demo in our assignment). However, creating actual content for these games in pure Haskell requires an understanding of the internal data structure which powers the game, and for the programmer to hard-code messages, links and other content into the type constructors. It would be nice to have a more human-friendly format for composing stories, which could then be loaded into our Haskell interactive player!

Enter Storyboard. The Storyboard Project is a platform which allows users to create complex, text-based stories using a friendly editor. These stories can then be exported in a JSON file containing encodings of all the information necessary to re-construct the story. This encoding is less than "readable", but if we could get this story information to our interactive player somehow, including all the required data structures, we would essentially have a means for user-friendly, non-programatic story creation.

What is the something extra?

We will use Haksell and the 'Aeson' JSON parsing library to construct a pipeline which converts Storyboard encoded story information into internal Haskell data-structures which represent games and can be played interactively. We will essentially be testing the feasibility of creating instances of Haskell datatypes from data in an arbitrary encoding (JSON in our case). This is somewhat analogous to byte-level data-structure interpretation in C, which provides a way to 'suck up information' and create internal program structs with little to no overhead. We will attempt to make our solution as algorithmically optimal as possible, in order to evaluate the feasibility of such transformations in Haskell.

If time permits, we will also create an end-to-end program which allows users to search for and download data from the Storyboard site, therefore eliminating the need to manually download story files.

What did we learn from doing this?

We learned a lot about the difference between solving small problems in assignments and creating large projects. We used Cabal to manage and install dependencies to our project, and had to read lots of documentation to successfully deploy the Aeson Library to parse JSON. We also ran into issues processing data from an external source which we do not control. The JSON files from the Storyboard Project are formatted unusually and are for the purpose of loading on the site; hence it has a lot of information that was unnecessary for our purpose. Finding workarounds for these issues taught us about Haskell's flexibility as a language and definitely the use-case for a strongly typed language.

The semantics and experience of parsing JSON in Haskell is surprising though-out and intuitive once one gets the hang of it. While it doesn't provide the convenient one-line parsing of JSON objects like you would find in Javascript, or even Python, Haskell's strong typing and Monadic approach to IO and error handling made the process of loading our data-structure much more methodical and less prone to random errors. Since the correspondence between the algebraic types we defined in Haskell and their appropriate parser instances have such strong pattern-matching requirements, our program fails very gracefully whenever it is given JSON without the required information. While Haskell might not be the ideal language for parsing JSON specifically, the characteristics described above make it a solid choice for doing reliable and systematic transformation of file data.


All of the code used in this project is contained in our GitHub repository.

We also learned a lot about Haskell JSON parsing from this tutorial.