I wrote a very simple raytracer in Haskell while first exploring the language. A raytracer felt natural because Haskell is mathematically elegant – certainly the rendering equation would be easy to express!
However, I quickly encountered problems:
When raytracing glass objects / mirrors, you need the rays to randomly bounce off the surface. Using randomness in Haskell is a nightmare because the language does not want functions to cause side-effects. This led to me using a library that encapsulates randomness as a
Monad
which is / was really difficult to grasp as a beginner.It’s slow. I think this can be fixed by writing to a file directly rather than writing to stdout.
I wanted to compile this project into WebAssembly which added an additional layer of complexity. The WASM compiler is still bleeding-edge and has few demos outside of a few articles and their gitlab. I really admire the work that the developers are doing, but I was not able to get my code ported to WASM.
You can find the source code here.