]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Misc.hs
Add the 'disjoint' function.
[spline3.git] / src / Misc.hs
index 090642a223d6e2f2493441445dcd1dfba8e5e969..b9220cbbcefa7bf52ea9ec6c76b5f5d09467d4b6 100644 (file)
@@ -3,6 +3,8 @@
 module Misc
 where
 
+import Data.List (intersect)
+
 
 -- | The standard factorial function. See
 --   <http://www.willamette.edu/~fruehr/haskell/evolution.html> for
@@ -47,7 +49,7 @@ transpose_xz m =
     where
       zsize = (length m) - 1
       ysize = length (head m) - 1
-      xsize = (length $ head $ head m) - 1
+      xsize = length (head $ head m) - 1
 
 -- | Takes a list, and returns True if its elements are pairwise
 --   equal. Returns False otherwise.
@@ -57,3 +59,19 @@ all_equal xs =
     where
       first_element  = head xs
       other_elements = tail xs
+
+
+-- | Returns 'True' if the lists xs and ys are disjoint, 'False'
+--   otherwise.
+--
+--   Examples:
+--
+--   >>> disjoint [1,2,3] [4,5,6]
+--   True
+--
+--   >>>  disjoint [1,2,3] [3,4,5]
+--   False
+--
+disjoint :: (Eq a) => [a] -> [a] -> Bool
+disjoint xs ys =
+    intersect xs ys == []