From: Michael Orlitzky Date: Mon, 5 Sep 2011 22:58:40 +0000 (-0400) Subject: Update the 'disjoint' function to work on Vectors instead of lists. X-Git-Tag: 0.0.1~154 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d2e1b5009ad0ae3595e874227586617aad068daa;p=spline3.git Update the 'disjoint' function to work on Vectors instead of lists. --- diff --git a/src/Misc.hs b/src/Misc.hs index 16b0ead..57dfd43 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -3,7 +3,7 @@ module Misc where -import Data.List (intersect) +import qualified Data.Vector as V (Vector, elem, empty, filter) import Test.Framework (Test, testGroup) import Test.Framework.Providers.HUnit (testCase) import Test.Framework.Providers.QuickCheck2 (testProperty) @@ -66,22 +66,27 @@ all_equal xs = other_elements = tail xs --- | Returns 'True' if the lists xs and ys are disjoint, 'False' +-- | Returns 'True' if the vectors xs and ys are disjoint, 'False' -- otherwise. -- -- Examples: -- --- >>> disjoint [1,2,3] [4,5,6] +-- >>> let xs = Data.Vector.fromList [1,2,3] +-- >>> let ys = Data.Vector.fromList [4,5,6] +-- >>> disjoint xs ys -- True -- --- >>> disjoint [1,2,3] [3,4,5] +-- >>> let ys = Data.Vector.fromList [3,4,5] +-- >>> disjoint xs ys -- False -- -disjoint :: (Eq a) => [a] -> [a] -> Bool +disjoint :: (Eq a) => V.Vector a -> V.Vector a -> Bool disjoint xs ys = - intersect xs ys == [] - - + intersect xs ys == V.empty + where + intersect :: (Eq a) => V.Vector a -> V.Vector a -> V.Vector a + intersect ws zs = + V.filter (`V.elem` zs) ws prop_factorial_greater :: Int -> Property prop_factorial_greater n =