{-# OPTIONS -fglasgow-exts -fbang-patterns  #-}

module OtherM where

import Foreign

{- MONOMORPHIC TYPE -}

data Vec3 = Vec3 {-# UNPACK #-} !Double
                 {-# UNPACK #-} !Double
                 {-# UNPACK #-} !Double
  deriving (Eq,Show)

vec3 !x !y !z = Vec3 x y z

instance Num Vec3 where
  (Vec3 a b c) + (Vec3 x y z) = Vec3 (a+x) (b+y) (c+z)

instance Storable Vec3 where
  sizeOf _ = 3 * sizeOf(undefined::Double)
  alignment _ = alignment (undefined::Double)
  peek !ptr = peek  (castPtr ptr)               >>= \x -> 
              peek ((castPtr ptr)`advancePtr`1) >>= \y -> 
              peek ((castPtr ptr)`advancePtr`2) >>= \z -> return (Vec3 x y z)

  poke !ptr !(Vec3 x y z) = 
             poke  (castPtr ptr)               x >>
             poke ((castPtr ptr)`advancePtr`1) y >>
             poke ((castPtr ptr)`advancePtr`2) z 
