
28 Nov
2006
28 Nov
'06
1:13 p.m.
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@gmail.com