Libraries

Published: 2021-05-18

I wasn't sure at the outset of this project how feasible it would be to do, so I thought I'd start by surveying what sort of library support there was for some of the features I knew I'd need.

Some programming concerns I was already fairly comfortable with the Haskell support for, such as reading config files, so didn't bother to include them in my investigative scope. Graphics I hadn't done in Haskell before, so that was included; and still other things, such as reading WAV files or playing audio, I'm pretty sure I hadn't done in any language before this project, so those were included as well.

WAV Files

To my delighted surprise, there are a fair number of Haskell libraries for reading WAV files. Some of these look to be wrappers around C libs, others are native Haskell libs.

I ended up choosing to go with the wave library, written in Haskell. Its API is delightfully simple and lets the consumer choose the in-program storage mechanism for the WAV data.

Graphics and Audio

Graphics and UI support was something I already knew Haskell had; I was aware that there were bindings for popular GUI toolkit libraries, such as GTK. But with a central feature of my application being the display of and interaction with WAV data, I figured I might be better off pushing my own pixels rather than relying on and trying to create custom components for a GUI toolkit, so I decided to investigate in that direction.

There are OpenGL bindings for Haskell, which would have been an option, but after a little thought I was struck by the notion that a gaming library would not only have support for graphics, but would also probably have support for audio playback!

After some searching I found the SDL2 library, which has support for graphics and audio output, has Haskell bindings, and is cross-platform too -- I wanted to be able to have both a PC and a Mac client, given my intended audience.

There are also extension SDL2 libraries for dealing with images and fonts, which I made use of as well.

Getting SDL2 and the bindings setup and running on both platforms was a bit of a pain; I'll go over the details of the trouble I ran into and how to get things running later on.