My dissertation this year has been on adding Simon Peyton Jones and Phil Wadlers Comprehensive Comprehensions to the Glasgow Haskell Compiler, and I might blog about that in the future. During this work, I needed to come up with some test cases for the generalized list comprehensions and so inspired by this post by LukeH I decided to implement a ray tracer in Haskell where all the raytracing logic is put within a single comprehension!

It turns out that the resulting program (which is heavily based on LukeH’s version) only needs to use one feature from the generalized comprehensions, but since it’s still pretty neat I thought you might be interested in seeing the (fairly crazy looking) inner loop:

Can you spot the generalized list comprehension feature that I’m using?

Here is the obligatory shot of some raytraced reflective colored spheres that it can produce:

Aww, ain’t that purdy? I’ll post the full code up here if anyone shows any interest, but be warned - it’s not nearly as pretty as the pictures it produces! I might be writing a further post about some of the more interesting techniques I’ve used within in, however..