X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FMisc.hs;h=9dcbac943b41c52f06b5140bfef8636eaafbb3e7;hb=cb5b361ea78acd6f8c04cd864adc15edd90299db;hp=48482b4f69a2cfe580b8b34a605beae82565168b;hpb=effb6b9a8716ce58fed6c8260c57164601a7df30;p=spline3.git diff --git a/src/Misc.hs b/src/Misc.hs index 48482b4..9dcbac9 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -25,10 +25,30 @@ factorial n -- | Takes a three-dimensional list, and flattens it into a -- one-dimensional one. +-- +-- Examples: +-- +-- >>> flatten [ [[1,2], [3,4]], [[5,6], [7,8]] ] +-- [1,2,3,4,5,6,7,8] +-- 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