Over a million developers have joined DZone.

Revolutionizing Mobile Gaming With Haskell and SDL

DZone's Guide to

Revolutionizing Mobile Gaming With Haskell and SDL

· Java Zone ·
Free Resource

"I love writing authentication and authorization code." ~ No Developer Ever. Try Okta Instead.

Since its creation, Haskell has developed a reputation for being efficient and cheap to implement. In enterprise settings, this is obviously ideal. Some companies use Haskell for automation, others for server implementation. Whatever their use may be, consistently, Haskell makes the lives of developers easier. But other than these server-side implementations, Haskell is oft-used for consumer-facing solutions.

And certainly no one has been writing Haskell apps for mobile devices.

Enter Keera Studios, a UK-based development company led by Ivan Perez that exclusively builds Haskell-based apps. They’re a small startup focusing on “using functional programming in Real World Applications”. They currently have a couple of Haskell desktop projects under their belt. It’s their belief that the future of mobile development is centered on functional programming (FP), so they wanted to experiment with creating a mobile game.

Keeping in the spirit of Haskell, Perez first needed to find a suitable API. He settled on Simple DirectMedia Layer (SDL), as it would enable him and his team to design the graphics easily enough of their own.

Next, they needed to settle on a compiler. Although Glasgow Haskell Compiler (GHC) does not officially support Android, there are enough workarounds to make things compatible.

Eventually, Perez and his team had to see if they could get an app to run. They immediately encountered issues.

The problem is that Android applications to be deployed on the market cannot be written this way. At least when it comes to SDL games, a Java application creates the drawing surface and calls SDLmain, which in turn executes our program. That means our program must be converted into a library, and our main (the Haskell program’s entry point) renamed.

After a great deal of research and hours of work, they finally had a demo module ready to test. The module was simple - set a background screen. And when they launched their app, they were ecstatic to find a beautiful green rectangle.

(Courtesy of Keera Studios)

Perez and his team were stoked.

When that happened, we were quite thrilled. To the inexperienced, this may look just like any green screen. But it meant much more. It meant that Haskell was running on an ARM Android device, and that Java was calling Haskell as C via it’s Foreign Function Interface (FFI), which in turn was executing correctly (including its Runtime System), and calling SDL’s C API also via the FFI.

It was at this point that their ambitions grew. Now that they knew they could create Haskell-based apps, they wanted to challenge themselves to creating a game. Days later, they had created a Breakout-esque game using the same engine that had produced their green screen.

(Courtesy of Keera Studios)

Their progress is astounding. Already, they’re working on a full scale Haskell game for Android. Along the way, they will be releasing their libraries for others to reference on their website. You can follow their progress on FacebookTwitter, and Github.

"I love writing authentication and authorization code." ~ No Developer Ever. Try Okta Instead.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}