Skip to content

Commit 2f1dd8b

Browse files
committed
cleaning up, minimizing Utils
1 parent 405ac6f commit 2f1dd8b

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

chr-data/src/CHR/Data/Lookup/Scoped.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ instance (Scoped scps, Lookup lkup k (ScopedItem v)) => Lookup (ScpsLkup lkup sc
185185
-- first a quick test, then the more expensive
186186
null l@(ScpsLkup lkup scps) = null lkup || List.null (toList l)
187187

188+
size l@(ScpsLkup lkup _) = size lkup
189+
188190
{-
189191
-- should restrict to items which are nested inside current scope
190192
findMin (ScpsLkup lkup scps) = second _scopeditemVal $ findMin lkup

chr-data/src/CHR/Utils.hs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module CHR.Utils
88
(
9+
{-
910
-- * Set
1011
unionMapSet
1112
@@ -18,18 +19,24 @@ module CHR.Utils
1819
-- * List
1920
, hdAndTl', hdAndTl
2021
, maybeNull
21-
, maybeHd
22+
-}
23+
maybeHd
24+
{-
2225
, wordsBy
2326
, initlast, initlast2
2427
, last'
2528
, firstNotEmpty
2629
, listSaturate, listSaturateWith
2730
, spanOnRest
2831
, filterMb
32+
-}
2933
, splitPlaces
3034
, combineToDistinguishedEltsBy
35+
{-
3136
, partitionOnSplit
37+
-}
3238
, zipWithN
39+
{-
3340
3441
-- * Tuple
3542
, tup123to1, tup123to2
@@ -82,19 +89,26 @@ module CHR.Utils
8289
, showUnprefixed
8390
8491
-- * Ordering
92+
-}
8593
, orderingLexic
94+
{-
8695
, orderingLexicList
8796
8897
-- * Misc
98+
-}
8999
, panic
90-
100+
{-
91101
, isSortedByOn
92102
, sortOnLazy
93103
, sortOn
104+
-}
94105
, sortByOn
106+
{-
95107
, groupOn
96108
, groupByOn
109+
-}
97110
, groupSortOn
111+
{-
98112
, groupSortByOn
99113
, nubOn
100114
@@ -115,6 +129,7 @@ module CHR.Utils
115129
-- * Monad
116130
, firstMaybeM
117131
, breakM
132+
-}
118133
)
119134
where
120135

@@ -128,6 +143,8 @@ import qualified Data.Set as Set
128143
import qualified Data.Map as Map
129144
-- import qualified Data.Graph as Graph
130145

146+
{-
147+
131148
-------------------------------------------------------------------------
132149
-- Set
133150
-------------------------------------------------------------------------
@@ -147,11 +164,13 @@ inverseMap mk = Map.fromList . map (uncurry mk) . Map.toList
147164
-- | Show keys of map using a separator
148165
showStringMapKeys :: Map.Map String x -> String -> String
149166
showStringMapKeys m sep = concat $ intersperse sep $ Map.keys m
167+
-}
150168

151169
-------------------------------------------------------------------------
152170
-- List
153171
-------------------------------------------------------------------------
154172

173+
{-
155174
-- | Get head and tail, with default if empty list
156175
hdAndTl' :: a -> [a] -> (a,[a])
157176
hdAndTl' _ (a:as) = (a,as)
@@ -161,6 +180,7 @@ hdAndTl' n [] = (n,[])
161180
hdAndTl :: [a] -> (a,[a])
162181
hdAndTl = hdAndTl' (panic "hdAndTl")
163182
{-# INLINE hdAndTl #-}
183+
-}
164184

165185
maybeNull :: r -> ([a] -> r) -> [a] -> r
166186
maybeNull n f l = if null l then n else f l
@@ -170,6 +190,7 @@ maybeHd :: r -> (a -> r) -> [a] -> r
170190
maybeHd n f = maybeNull n (f . head)
171191
{-# INLINE maybeHd #-}
172192

193+
{-
173194
-- | Split up in words by predicate
174195
wordsBy :: (a -> Bool) -> [a] -> [[a]]
175196
wordsBy p l
@@ -236,6 +257,8 @@ filterMb :: (a -> Maybe b) -> [a] -> [b]
236257
filterMb p = catMaybes . map p
237258
{-# INLINE filterMb #-}
238259
260+
-}
261+
239262
-- | Split at index places (inspired by/from split package). Places should be increasing, starting with an index >= 0.
240263
-- The number of sublists returned is one higher than the number of places.
241264
--
@@ -279,6 +302,8 @@ zipWithN :: ([x] -> y) -> [[x]] -> [y]
279302
zipWithN f l | any null l = []
280303
| otherwise = f (map head l) : zipWithN f (map tail l)
281304

305+
{-
306+
282307
-------------------------------------------------------------------------
283308
-- Tupling, untupling
284309
-------------------------------------------------------------------------
@@ -353,6 +378,7 @@ fth = fth4
353378
{-# INLINE fth4 #-}
354379
{-# INLINE fth #-}
355380
381+
356382
-------------------------------------------------------------------------
357383
-- String
358384
-------------------------------------------------------------------------
@@ -434,6 +460,9 @@ splitForQualified s
434460
(nq,(_:ns)) -> nq ++ [concatMap ("."++) ns]
435461
_ -> ws'
436462
463+
-}
464+
465+
437466
-------------------------------------------------------------------------
438467
-- Misc
439468
-------------------------------------------------------------------------
@@ -445,6 +474,8 @@ panic m = error ("panic: " ++ m)
445474
-- group/sort/nub combi's
446475
-------------------------------------------------------------------------
447476

477+
{-
478+
448479
isSortedByOn :: (b -> b -> Ordering) -> (a -> b) -> [a] -> Bool
449480
isSortedByOn cmp sel l
450481
= isSrt l
@@ -457,6 +488,8 @@ sortOnLazy :: Ord b => (a -> b) -> [a] -> [a]
457488
sortOnLazy = sortByOn compare
458489
{-# INLINE sortOnLazy #-}
459490
491+
-}
492+
460493
#if __GLASGOW_HASKELL__ >= 710
461494
#else
462495
-- | The original Data.List.sortOn.
@@ -466,6 +499,7 @@ sortOn = sortOnLazy
466499
{-# INLINE sortOn #-}
467500
#endif
468501

502+
469503
sortByOn :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [a]
470504
sortByOn cmp sel = sortBy (cmp `on` sel) -- (\e1 e2 -> sel e1 `cmp` sel e2)
471505

@@ -475,6 +509,7 @@ groupOn sel = groupBy ((==) `on` sel) -- (\e1 e2 -> sel e1 == sel e2)
475509
groupSortOn :: Ord b => (a -> b) -> [a] -> [[a]]
476510
groupSortOn sel = groupOn sel . sortOn sel
477511

512+
{-
478513
groupByOn :: (b -> b -> Bool) -> (a -> b) -> [a] -> [[a]]
479514
groupByOn eq sel = groupBy (eq `on` sel) -- (\e1 e2 -> sel e1 `eq` sel e2)
480515
@@ -499,6 +534,7 @@ partitionOnSplit split adapt pred xs = foldr sel ([],[]) xs
499534
where sel x ~(ts,fs) | pred x' = ((adapt x',y):ts, fs)
500535
| otherwise = ( ts, y:fs)
501536
where (x',y) = split x
537+
-}
502538

503539
{-
504540
partition :: (a -> Bool) -> [a] -> ([a],[a])
@@ -510,6 +546,7 @@ select p x ~(ts,fs) | p x = (x:ts,fs)
510546
| otherwise = (ts, x:fs)
511547
-}
512548

549+
{-
513550
-------------------------------------------------------------------------
514551
-- Partitioning with rebuild
515552
-------------------------------------------------------------------------
@@ -522,6 +559,8 @@ partitionAndRebuild f (v:vs)
522559
where (vs1,vs2,mk) = partitionAndRebuild f vs
523560
partitionAndRebuild _ [] = ([], [], \_ _ -> [])
524561
562+
-}
563+
525564
-------------------------------------------------------------------------
526565
-- Ordering
527566
-------------------------------------------------------------------------
@@ -536,10 +575,13 @@ orderingLexic :: Ordering -> Ordering -> Ordering
536575
orderingLexic o1 o2 = if o1 == EQ then o2 else o1
537576
{-# INLINE orderingLexic #-}
538577

578+
{-
579+
539580
-------------------------------------------------------------------------
540581
-- Maybe
541582
-------------------------------------------------------------------------
542583
584+
543585
panicJust :: String -> Maybe a -> a
544586
panicJust m = maybe (panic m) id
545587
{-# INLINE panicJust #-}
@@ -569,6 +611,8 @@ maybeOr n fa fb ma mb
569611
Just b -> fb b
570612
_ -> n
571613
614+
-}
615+
572616
-------------------------------------------------------------------------
573617
-- Strongly Connected Components
574618
-------------------------------------------------------------------------
@@ -578,6 +622,7 @@ scc :: Ord n => [(n,[n])] -> [[n]]
578622
scc = map Graph.flattenSCC . Graph.stronglyConnComp . map (\(n,ns) -> (n, n, ns))
579623
-}
580624

625+
{-
581626
-------------------------------------------------------------------------
582627
-- Map
583628
-------------------------------------------------------------------------
@@ -609,3 +654,7 @@ breakM :: Monad m => (a -> Bool) -> [m a] -> m ([a], Maybe (a,[m a]))
609654
breakM p l = br [] l >>= \(acc,res) -> return (reverse acc, res)
610655
where br acc [] = return (acc, Nothing)
611656
br acc (m:ms) = m >>= \x -> if p x then return (acc, Just (x, ms)) else br (x:acc) ms
657+
658+
-}
659+
660+

0 commit comments

Comments
 (0)