data Quaternion =
     Q Double Double Double Double
       deriving (Eq, Show)

scalar s = Q s 0 0 0

addQ (Q a b c d) (Q w x y z) =
  Q (a+w) (b+x) (c+y) (d+z)

subQ (Q a b c d) (Q w x y z) =
  Q (a-w) (b-x) (c-y) (d-z)

mulQ (Q s1 x1 y1 z1) (Q s2 x2 y2 z2)
  = Q (s1 * s2 - x1 * x2 - y1 * y2 - z1 * z2)
      (s1 * x2 + x1 * s2 + y1 * z2 - z1 * y2)
      (s1 * y2 - x1 * z2 + y1 * s2 + z1 * x2)
      (s1 * z2 + x1 * y2 - y1 * x2 + z1 * s2)

