Most existing approaches to writing games in Haskell are quite complicated. Often you have to deal with rather imperative low-level APIs (such as OpenGL) or you need to get your head around a sophisticated FRP library (such as Yampa or reactive-banana). In any case, the actual game-related functionality is usually rather limited (unless you code yourself all the way up from the likes of OpenGL and implement your own physics engine).

Now there is an alternative that is simultaneously more convenient and more powerful: Haskell SpriteKit provides a purely functional, easy-to-use binding to a modern industrial-strength gaming framework. The price? Your are limited to 2D games on Apple platforms.

  • It is purely functional as it uses an approach not unlike React (Native)'s virtual DOM to translate purely functional state transformers into edits of the underlying object graph representing the game scene.
  • It is easy-to-use as all data structures are simple algebraic data types manipulated by pure functions.
  • It is modern and powerful as it is based on Apple's SpriteKit framework — a state-of-the-art framework including a versatile animation system and physics engine.

If you like to know more, in the opening keynote of Compose :: Melbourne, I explain the basic architecture of Haskell SpriteKit and live code a Flappy Bird clone, called Lazy Lambda, in Haskell in less than 20 minutes: video and slides. (I obviously used pre-defined code snippets, but I think you'd be hard pressed to do this with any other Haskell game framework.)

The code for Lazy Lambda and Haskell SpriteKit are open source on GitHub: check out Lazy Lambda repo & Haskell SpriteKit repo.

Getting started with Haskell SpriteKit is easy: just load the Lazy Lambda project into Haskell for Mac, which includes SpriteKit support out-of-the-box, and start tweaking it. Give it a try, and start writing a game in Haskell!