summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Tools.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/Tools.hs')
-rw-r--r--packages/base/src/Internal/Tools.hs61
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
9module Internal.Tools where
10
11import Data.List(transpose,intersperse)
12import Foreign.C.Types(CInt)
13import Data.List.Split
14
15type I = CInt
16
17splitEvery :: Int -> [e] -> [[e]]
18splitEvery = chunksOf
19
20-- | postfix function application (@flip ($)@)
21(//) :: x -> (x -> y) -> y
22infixl 0 //
23(//) = flip ($)
24
25-- | specialized fromIntegral
26fi :: Int -> CInt
27fi = fromIntegral
28
29-- | specialized fromIntegral
30ti :: CInt -> Int
31ti = fromIntegral
32
33-- | obtains the common value of a property of a list
34common :: (Eq a) => (b->a) -> [b] -> Maybe a
35common 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
43compatdim :: [Int] -> Maybe Int
44compatdim [] = Nothing
45compatdim [a] = Just a
46compatdim (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
53table :: String -> [[String]] -> String
54table 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