I'd like to use some OpenGL resources (VBOs, textures, shaders, and shader programs) in a functional way, with immutability, garbage collection, and IO-free creation interfaces. Has anyone played with doing such a thing? I guess the GC part would involve foreign pointers with foreign finalizers (which now run promptly in GHC iiuc). I don't know of any reliable way to add finalizers to Ptr values, because of the unboxing problem [1].
One tricky issue is that graphics context initialization must take place before any of these "pure" resources get evaluated. If the APIs allowed access to to multiple graphics contexts, things would get stickier.
Comments?
- Conal
[1] http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html#v%3AaddFinalizer