Permalink
Browse files

Compile module with NoMonophormismRestriction.

This allows a friendly ghci interface for playing with vectors.
  • Loading branch information...
1 parent 4d136cf commit 8213b69a1c2c84ab646d3f60c2e68ceed7c8bf19 @creichert committed Jan 28, 2012
Showing with 8 additions and 5 deletions.
  1. +2 −0 linear-hs.cabal
  2. +4 −4 src/Numeric/Vector.hs
  3. +2 −1 test/Test/Vector.hs
View
@@ -9,6 +9,7 @@ cabal-version: >= 1.2.3
Library
hs-source-dirs: src
+ extensions: NoMonomorphismRestriction
exposed-modules: Numeric.Vector,
Numeric.Matrix,
Math.LinearAlgebra
@@ -17,6 +18,7 @@ Library
Executable linear-hs-tests
hs-source-dirs: src, test
main-is: Main.hs
+ extensions: NoMonomorphismRestriction
other-modules: Test.Vector,
Numeric.Vector,
Math.LinearAlgebra
View
@@ -94,7 +94,7 @@ normalize :: (Real a, Floating a) => Vector a -> Vector a
normalize v = multScalar (recip $ magnitude v) v
-- | Take the cross product of a 2 or 2 dimensional 'Vector'
-cross :: (Num a, Fractional a) => Vector a -> Vector a -> Vector a
+cross :: (Num a) => Vector a -> Vector a -> Vector a
cross (Vector n xs) (Vector m ys)
| n == 3 && m == 3 = cross3D' (Vector n xs) (Vector m ys)
| n == 2 && m == 2 = cross2D' (Vector n xs) (Vector m ys)
@@ -107,16 +107,16 @@ cross3D' (Vector _ xs) (Vector _ ys) = mkVector [ xs!!1 * ys!!2 - xs!!2 * ys!!1,
head xs * ys!!1 - xs!!1 * head ys]
-- internal cross product of 2D vector.
-cross2D' :: (Num a, Fractional a) => Vector a -> Vector a -> Vector a
+cross2D' :: (Num a) => Vector a -> Vector a -> Vector a
cross2D' (Vector _ xs) (Vector _ ys) = mkVector [0,0, crossLists]
where crossLists = head xs * ys!!1 - xs!!1 * head ys
-- | Determine whether two vectors are parallel.
-(//) :: (Num a, Fractional a) => Vector a -> Vector a -> Bool
+(//) :: (Num a) => Vector a -> Vector a -> Bool
v // w = parallel v w
-- | Determine whether two vectors are parallel. See '(//)'.
-parallel :: (Num a, Fractional a) => Vector a -> Vector a -> Bool
+parallel :: (Num a) => Vector a -> Vector a -> Bool
parallel v w = v `cross` w == Vector dim [0,0,0]
where dim = max (dimensions v) (dimensions w)
View
@@ -25,7 +25,7 @@ import Numeric.Vector ( Vector(..)
, angle
, cross
, perpindicular
- , parallel )
+ , (//), parallel )
--------------------------------- HUnit Tests --------------------------------
@@ -89,6 +89,7 @@ utests_Vector = TestList [ TestLabel "test angle1" test_angle1
, TestLabel "test parallel4" test_parallel4
, TestLabel "test parallel5" test_parallel5
, TestLabel "test parallel6" test_parallel6
+ , TestLabel "test parallel7" test_parallel7
]

0 comments on commit 8213b69

Please sign in to comment.