Up to now, we’re using Quaazar.Render.GL to implement a little thin OpenGL wrapper. That one is basically running (ruining?) in MonadIO m and is straightforwardly performing bare and direct OpenGL calls from the gl package. We then lose Foreign code from the interface with OpenGL, which is great. Apart that, we add nothing more.
OpenGL is a (fucking) state machine. Up to now, we don’t track any state. We just ensure that we don’t fuck up with the state, as all imperative dudes. And as all imperative dudes, we fuck the state up from time to time. That’s boring because fucking with OpenGL means only one thing. This:
Yeah, right? Fucking annoying. I’ve been looking for weeks how to prevent that from happening by lifting runtime errors to compile-time. And I found nothing.
Indexed monads
Indexed monads can be used to implement compile-time tracking of the OpenGL (fucking) state machine. The basic idea is the following:
class IxApplicative f where
ipure :: a -> f i i a
iap :: f i j (a -> b) -> f j k a -> f i k b
class (IxApplicative m) => IxMonad m where
ibind :: f i j a -> (a -> f j k b) -> f i k b
And some kind of state to follow to replace i and j by.
Context
Up to now, we’re using
Quaazar.Render.GL
to implement a little thin OpenGL wrapper. That one is basically running (ruining?) inMonadIO m
and is straightforwardly performing bare and direct OpenGL calls from thegl
package. We then loseForeign
code from the interface with OpenGL, which is great. Apart that, we add nothing more.OpenGL is a (fucking) state machine. Up to now, we don’t track any state. We just ensure that we don’t fuck up with the state, as all imperative dudes. And as all imperative dudes, we fuck the state up from time to time. That’s boring because fucking with OpenGL means only one thing. This:
Yeah, right? Fucking annoying. I’ve been looking for weeks how to prevent that from happening by lifting runtime errors to compile-time. And I found nothing.
Indexed monads
Indexed monads can be used to implement compile-time tracking of the OpenGL (fucking) state machine. The basic idea is the following:
And some kind of state to follow to replace
i
andj
by.