X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMisc.hs;h=b9220cbbcefa7bf52ea9ec6c76b5f5d09467d4b6;hb=b2e1c440b9b1bb99ae564d6600230bbd1f7d204c;hp=34c682e31a7609e590898311885ea397fed1f6c4;hpb=26f0a2204a0bdb41b1d6aa5430544c404b77e638;p=spline3.git diff --git a/src/Misc.hs b/src/Misc.hs index 34c682e..b9220cb 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -3,6 +3,8 @@ module Misc where +import Data.List (intersect) + -- | The standard factorial function. See -- for @@ -35,6 +37,20 @@ flatten :: [[[a]]] -> [a] flatten xs = concat $ concat xs +-- | Switch the x and z dimensions of a three-dimensional list. +transpose_xz :: [[[a]]] -> [[[a]]] +transpose_xz [] = [] +transpose_xz [[]] = [[]] +transpose_xz [[[]]] = [[[]]] +transpose_xz m = + [[[ m !! x !! y !! z | x <- [0..xsize]] + | y <- [0..ysize]] + | z <- [0..zsize]] + where + zsize = (length m) - 1 + ysize = length (head m) - 1 + xsize = length (head $ head m) - 1 + -- | Takes a list, and returns True if its elements are pairwise -- equal. Returns False otherwise. all_equal :: (Eq a) => [a] -> Bool @@ -43,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 == []