Effectful Haskell with gloss
By now I am well past writing only pure functional Haskell (besides, solving problems from Project Euler is a bit dry in the long run). Avoiding side-effects does not get you very far when you want to use a programming language for solving problems in the real world. Any kind of output (or reading non-deterministic input) shifts you back on the path of impure (aka effectful) programming. Me being me, the “effects” I enjoy writing the most are from the field of computer graphics. While not yet fluent enough for a Haskell-implementation of a ray- or path-tracer, I can wield the language sufficiently enough to write some implementations of other typical computer-graphic algorithms.
I sat down and wrote Haskell-gimmicks for…
- 2D cubic bézier-curves
- 3D cubic bézier-patches
- 3D perspective camera projection and 3D transformations
In the screenshot above you see the examples running under Windows, which I did to flex the cross-platform muscle of Haskell or rather its most prominent compiler ghc. The code is available on my github-account here…
As a convenience tool, I made use of the Haskell library gloss, which provides basic 2D vector-graphics with an OpenGL-based rendering backend. Think cairo, but not as extensive, although with built-in accelaration and window-system-integration. Feature-wise it feels like an odd intersection of cairo, SDL and OpenGL.