[Haskell-cafe] Decoupling OpenAL/ALUT packages from OpenGL
Sven.Panne at aedion.de
Sun May 10 07:50:08 EDT 2009
Am Montag, 4. Mai 2009 13:33:33 schrieb David Duke:
> Decoupling basic primitives for geometric modelling from OpenGL would be
> useful. [...]
> Even just data constructors and instances of these within Functor and
> Applicative are a useful starting point. [...]
I've taken a closer look at the available packages for vector math/linear
algebra. They differ in a lot of respects, starting from their representations
of vectors and matrices, use of the type system and its extensions,
strictness, structure of their type classes, etc.
This leads me to the conclusion that I should only lift the data types for
vectors and matrices out of the OpenGL package, including only instances for
standard type classes like Eq, Ord, Functor, etc. This means that the new
package will *not* include type classes for things like scalars, vector
spaces, etc. These can be defined by the other packages in their own "type
class language". I really fail to see a common ground in this respect, even
for basic things: Keeping things H98-compliant is a must for me, so putting
things like fundeps or associated types in this new package is a no-go for me.
Nevertheless, having a common set of (strict) data types for vector math will
probably be very useful, even if it won't fulfill everybody's needs.
What standard instances should be defined for those vectors and matrices?
Things coming to mind are Eq, Ord, Show, Storable, Typeable1, Functor and
Applicative. Have I missed some type classes?
Regarding Functor/Applicative: The obvious instances for e.g. a 2-dimensional
data Vertex2 a = Vertex2 a a
instance Functor Vertex2 where
fmap f (Vertex2 x y) = Vertex2 (f x) (f y)
instance Applicative Vertex2 where
pure a = Vertex2 a a
Vertex2 f g <*> Vertex2 x y = Vertex2 (f x) (g y)
They fulfill all required laws, but are these the only possible instances? If
not, are they at least the most "canonical" ones in a given sense? And
finally: Does somebody have a real-world example where the Applicative
instance is useful? Usages of the Functor instance are much more obvious for
More information about the Haskell-Cafe