
On 11/28/06, Slavomir Kaslev
On 11/28/06, Bulat Ziganshin
wrote: 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
I wasn't aware of parameterized types, they are sweet. Thank you very much.
What about my other questions? Do you have any suggestions? I know that this is very library specific. All I am asking is for some Haskell common sense. What would you do, if you were writing this kind of library?
Cheers.
-- Slavomir Kaslev
Err... Actually I *am* aware of parameterized types. Almost every function function from the Prelude on lists is parameterized. I was confused by you post that parameterized types have something to do with the strictness flag '!'. Sorry for that, going home embarrassed. -- Slavomir Kaslev