diff options
Diffstat (limited to 'packages/base/src/Internal/Tools.hs')
-rw-r--r-- | packages/base/src/Internal/Tools.hs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/packages/base/src/Internal/Tools.hs b/packages/base/src/Internal/Tools.hs deleted file mode 100644 index 47115bc..0000000 --- a/packages/base/src/Internal/Tools.hs +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | -- | | ||
2 | -- Module : Internal.Tools | ||
3 | -- Copyright : (c) Alberto Ruiz 2007-15 | ||
4 | -- License : BSD3 | ||
5 | -- Maintainer : Alberto Ruiz | ||
6 | -- Stability : provisional | ||
7 | -- | ||
8 | |||
9 | module Internal.Tools where | ||
10 | |||
11 | import Data.List(transpose,intersperse) | ||
12 | import Foreign.C.Types(CInt) | ||
13 | import Data.List.Split | ||
14 | |||
15 | type I = CInt | ||
16 | |||
17 | splitEvery :: Int -> [e] -> [[e]] | ||
18 | splitEvery = chunksOf | ||
19 | |||
20 | -- | postfix function application (@flip ($)@) | ||
21 | (//) :: x -> (x -> y) -> y | ||
22 | infixl 0 // | ||
23 | (//) = flip ($) | ||
24 | |||
25 | -- | specialized fromIntegral | ||
26 | fi :: Int -> CInt | ||
27 | fi = fromIntegral | ||
28 | |||
29 | -- | specialized fromIntegral | ||
30 | ti :: CInt -> Int | ||
31 | ti = fromIntegral | ||
32 | |||
33 | -- | obtains the common value of a property of a list | ||
34 | common :: (Eq a) => (b->a) -> [b] -> Maybe a | ||
35 | common f = commonval . map f | ||
36 | where | ||
37 | commonval :: (Eq a) => [a] -> Maybe a | ||
38 | commonval [] = Nothing | ||
39 | commonval [a] = Just a | ||
40 | commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing | ||
41 | |||
42 | -- | common value with \"adaptable\" 1 | ||
43 | compatdim :: [Int] -> Maybe Int | ||
44 | compatdim [] = Nothing | ||
45 | compatdim [a] = Just a | ||
46 | compatdim (a:b:xs) | ||
47 | | a==b = compatdim (b:xs) | ||
48 | | a==1 = compatdim (b:xs) | ||
49 | | b==1 = compatdim (a:xs) | ||
50 | | otherwise = Nothing | ||
51 | |||
52 | -- | Formatting tool | ||
53 | table :: String -> [[String]] -> String | ||
54 | table sep as = unlines . map unwords' $ transpose mtp | ||
55 | where | ||
56 | mt = transpose as | ||
57 | longs = map (maximum . map length) mt | ||
58 | mtp = zipWith (\a b -> map (pad a) b) longs mt | ||
59 | pad n str = replicate (n - length str) ' ' ++ str | ||
60 | unwords' = concat . intersperse sep | ||
61 | |||