[Haskell-cafe] [Haskell] Defining Cg, HLSL style vectors in Haskell

Henning Thielemann lemming at henning-thielemann.de
Wed Nov 29 06:16:11 EST 2006


On Tue, 28 Nov 2006, Brian Hulley wrote:

> While it may be tempting to want to use symbolic operators like + and -,
> these quickly become very confusing when more distinctions need to be made
> (eg between cross product, dot product, and scaling, or between transforming
> a position versus transforming a direction) so I'd argue that for
> readability descriptive names are better than symbols:
>
>     class Num a => Vector v a where
>         plus :: v a -> v a -> v a
>         minus :: v a -> v a -> v a
>         cross :: v a -> v a -> v a
>         dot :: v a -> v a -> a
>         scale :: a -> v a -> v a
>         magSquared :: v a -> a

I'm currently even thinking about an alternative of the multi-parameter
class Vector that is Haskell 98. The problem with the multi-parameter type
class is, that you cannot define instances where 'a' is a complex number
type, say
  Num a => Vector [Complex a] (Complex a)


More information about the Haskell-Cafe mailing list