On Fri, Jun 25, 2010 at 12:41:48AM +0400, Alexey Khudyakov wrote:
> Then constructor like one below arise naturally. And I don't know how to write
> them properly. It's possible to use fromList but then list could be allocated
> which is obviously wasteful.

Did you see the generated core?  I think you should give a try to
the following simple code:

  import qualified Data.Vector.Generic as VG -- vector == 0.6.*

  vector2 :: Double -> Double -> Vec2D
  vector2 x y = Vec2D (VG.fromListN 2 [x,y])

> Another question is there any specific problems with short vectors? They could
> be just 2 elements long. I mean performance problems

Probably there will be more overhead than defining

  data Vec2D = Vec2D {-# UNPACK #-} !Double
                     {-# UNPACK #-} !Double

You should profile to see how much difference there is between
those representations.

Cheers,

--
Felipe.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to