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

Bulat Ziganshin bulat.ziganshin at gmail.com
Tue Nov 28 08:13:30 EST 2006

Hello Slavomir,

Tuesday, November 28, 2006, 3:46:13 PM, you wrote:

> Last question: Does haskell have something like C++ templates? For
> example, some time in the future I may need types like int2, short3,
> etc., that behave just like float2, float3, but use different types
> for their components. I really, really wouldn't like to copy-paste the
> definitions of floatn and manually change their types to intn
> respectfully.

yes, it's named parameterized types:

data Vec2 a = Vec2 !a !a

instance (Num a) => Num (Vec2 a) where
   (Vec2 a1 a2) + (Vec2 b1 b2) = Vec2 (a1+b1) (a2+b2)

type Float2 = Vec2 Float

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list