The TARDIS from Doctor Who

Image credit: BBC

Elm Time Travel

This assignment provides to you two small video games written in Elm. You will write code that can take any arbitrary Elm game, and add time travel to it.

How is this possible? An Elm application is a collection of several functions that work together to manage the application’s state. One creates the initial state. One updates the state based on user input and/or time passing. One displays the current state on the screen. All these functions have one thing in common: they are pure functions, meaning their only input is their parameters, and their only output is their return value.

Because the app is just a few functions, you can take a whole application as a value and wrap your own behavior around those functions. And because they are pure functions, if you remember all the inputs that came in, you can accurately reproduce the entire state of the application at any point in time by reapplying the functions! Thus time travel consists of three things:

  • Remember all the input data that came to the application.
  • Implement the ability to recreate past application states using all that saved input data.
  • Build a user interface to pause the app, travel back to a past state, and then resume.
  • Gain familiarity with purely functional programming in general.
  • Gain familiarity with a statically typed functional language in particular.
  • Begin to understand the possibilities and limitations this model of programming creates, by doing something nifty that would be very difficult to do in a language with side effects.