uhc-util 0.1.5.1 → 0.1.5.2
raw patch · 6 files changed
+115/−12 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- src/UHC/Util/Lens.hs +1/−1
- src/UHC/Util/ParseUtils.hs +6/−1
- src/UHC/Util/Serialize.hs +1/−0
- src/UHC/Util/Utils.hs +88/−5
- src/UHC/Util/VarLookup.hs +18/−4
- uhc-util.cabal +1/−1
src/UHC/Util/Lens.hs view
@@ -53,7 +53,7 @@ -- * Operator interface for composition infixl 9 ^*--- | functional getter, which acts like a field accessor+-- | composition (^*) :: (a :-> b) -> (b :-> c) -> (a :-> c) f1 ^* f2 = f2 . f1 {-# INLINE (^*) #-}
src/UHC/Util/ParseUtils.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE RankNTypes, FlexibleContexts #-}+{-# LANGUAGE RankNTypes, FlexibleContexts, CPP #-} module UHC.Util.ParseUtils ( -- * Specific parser types@@ -26,6 +26,11 @@ , fromMessage ) where++#if __GLASGOW_HASKELL__ >= 710+import Prelude hiding ( (<*>), (<*), (*>), (<$>), (<$) )+#else+#endif import qualified Data.Map as Map import Data.Maybe
src/UHC/Util/Serialize.hs view
@@ -67,6 +67,7 @@ {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE FlexibleContexts #-} module UHC.Util.Serialize ( SPut
src/UHC/Util/Utils.hs view
@@ -1,5 +1,71 @@-module UHC.Util.Utils where+{-# LANGUAGE CPP #-} +module UHC.Util.Utils+ ( -- * Set+ unionMapSet++ -- * Map+ , inverseMap+ , showStringMapKeys+ + , mapLookup2', mapLookup2+ + -- * List+ , hdAndTl', hdAndTl+ , maybeNull, maybeHd+ , wordsBy+ , initlast, initlast2+ , last'+ , firstNotEmpty+ , listSaturate, listSaturateWith+ , spanOnRest+ + -- * Tuple+ , tup123to1, tup123to2+ , tup123to12, tup123to23+ , tup12to123++ -- * String+ , strWhite+ , strPad+ , strCapitalize+ , strToInt+ + , splitForQualified+ + -- * Misc+ , panic+ + , isSortedByOn+ , sortOn+ , sortByOn+ , groupOn+ , groupByOn+ , groupSortOn+ , groupSortByOn+ , nubOn+ + , consecutiveBy+ + , partitionAndRebuild+ + , orderingLexic+ + -- * Maybe+ , panicJust+ , ($?)+ , orMb+ , maybeAnd+ , maybeOr+ + -- * Graph+ , scc+ + -- * MOnad+ , firstMaybeM+ )+ where+ -- import UHC.Util.Pretty import Data.Char import Data.List@@ -11,6 +77,7 @@ -- Set ------------------------------------------------------------------------- +-- | Union a set where each element itself is mapped to a set unionMapSet :: Ord b => (a -> Set.Set b) -> (Set.Set a -> Set.Set b) unionMapSet f = Set.unions . map f . Set.toList @@ -18,9 +85,11 @@ -- Map ------------------------------------------------------------------------- +-- | Inverse of a map inverseMap :: (Ord k, Ord v') => (k -> v -> (v',k')) -> Map.Map k v -> Map.Map v' k' inverseMap mk = Map.fromList . map (uncurry mk) . Map.toList +-- | Show keys of map using a separator showStringMapKeys :: Map.Map String x -> String -> String showStringMapKeys m sep = concat $ intersperse sep $ Map.keys m @@ -28,10 +97,12 @@ -- List ------------------------------------------------------------------------- +-- | Get head and tail, with default if empty list hdAndTl' :: a -> [a] -> (a,[a]) hdAndTl' _ (a:as) = (a,as) hdAndTl' n [] = (n,[]) +-- | Get head and tail, with panic/error if empty list hdAndTl :: [a] -> (a,[a]) hdAndTl = hdAndTl' (panic "hdAndTl") {-# INLINE hdAndTl #-}@@ -44,6 +115,7 @@ maybeHd n f = maybeNull n (f . head) {-# INLINE maybeHd #-} +-- | Split up in words by predicate wordsBy :: (a -> Bool) -> [a] -> [[a]] wordsBy p l = w l@@ -53,6 +125,7 @@ (_:[]) -> [[]] (_:ls'') -> w ls'' +-- | Possibly last element and init initlast :: [a] -> Maybe ([a],a) initlast as = il [] as@@ -64,6 +137,7 @@ last' :: a -> [a] -> a last' e = maybe e snd . initlast +-- | Possibly last and preceding element and init initlast2 :: [a] -> Maybe ([a],a,a) initlast2 as = il [] as@@ -71,24 +145,23 @@ il acc (a:as) = il (a:acc) as il _ _ = Nothing +-- | First non empty list of list of lists firstNotEmpty :: [[x]] -> [x] firstNotEmpty = maybeHd [] id . filter (not . null) --- saturate a list, that is:+-- | Saturate a list, that is: -- for all indices i between min and max, -- if there is no listelement x for which get x returns i, -- add an element mk i to the list- listSaturate :: (Enum a,Ord a) => a -> a -> (x -> a) -> (a -> x) -> [x] -> [x] listSaturate min max get mk xs = [ Map.findWithDefault (mk i) i mp | i <- [min..max] ] where mp = Map.fromList [ (get x,x) | x <- xs ] --- saturate a list with values from assoc list, that is:+-- | Saturate a list with values from assoc list, that is: -- for all indices i between min and max, -- if there is no listelement x for which get x returns i, -- add a candidate from the associationlist (which must be present) to the list- listSaturateWith :: (Enum a,Ord a) => a -> a -> (x -> a) -> [(a,x)] -> [x] -> [x] listSaturateWith min max get missing l = listSaturate min max get mk l@@ -123,19 +196,23 @@ -- String ------------------------------------------------------------------------- +-- | Blanks strWhite :: Int -> String strWhite sz = replicate sz ' ' {-# INLINE strWhite #-} +-- | Pad upto size with blanks strPad :: String -> Int -> String strPad s sz = s ++ strWhite (sz - length s) +-- | Capitalize first letter strCapitalize :: String -> String strCapitalize s = case s of (c:cs) -> toUpper c : cs _ -> s +-- | Convert string to Int strToInt :: String -> Int strToInt = foldl (\i c -> i * 10 + ord c - ord '0') 0 @@ -143,6 +220,7 @@ -- Split for qualified name ------------------------------------------------------------------------- +-- | Split into fragments based on '.' convention for qualified Haskell names splitForQualified :: String -> [String] splitForQualified s = ws''@@ -158,6 +236,7 @@ -- Misc ------------------------------------------------------------------------- +-- | Error, with message panic m = error ("panic: " ++ m) -------------------------------------------------------------------------@@ -170,9 +249,12 @@ where isSrt (x1:tl@(x2:_)) = cmp (sel x1) (sel x2) /= GT && isSrt tl isSrt _ = True +#if __GLASGOW_HASKELL__ >= 710+#else sortOn :: Ord b => (a -> b) -> [a] -> [a] sortOn = sortByOn compare {-# INLINE sortOn #-}+#endif sortByOn :: (b -> b -> Ordering) -> (a -> b) -> [a] -> [a] sortByOn cmp sel = sortBy (\e1 e2 -> sel e1 `cmp` sel e2)@@ -217,6 +299,7 @@ -- Ordering ------------------------------------------------------------------------- +-- | Reduce compare results lexicographically to one compare result orderingLexic :: [Ordering] -> Ordering orderingLexic = foldr1 (\o1 o2 -> if o1 == EQ then o2 else o1)
src/UHC/Util/VarLookup.hs view
@@ -2,7 +2,11 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 710+#else {-# LANGUAGE OverlappingInstances #-}+#endif module UHC.Util.VarLookup ( VarLookup (..)@@ -79,11 +83,21 @@ class VarLookupCmb m1 m2 where (|+>) :: m1 -> m2 -> m2 -instance VarLookupCmb m1 m2 => VarLookupCmb m1 [m2] where- m1 |+> (m2:m2s) = (m1 |+> m2) : m2s+#if __GLASGOW_HASKELL__ >= 710+instance {-# OVERLAPPING #-}+#else+instance+#endif+ VarLookupCmb m1 m2 => VarLookupCmb m1 [m2] where+ m1 |+> (m2:m2s) = (m1 |+> m2) : m2s -instance (VarLookupCmb m1 m1, VarLookupCmb m1 m2) => VarLookupCmb [m1] [m2] where- m1 |+> (m2:m2s) = (foldr1 (|+>) m1 |+> m2) : m2s+#if __GLASGOW_HASKELL__ >= 710+instance {-# OVERLAPPING #-}+#else+instance+#endif+ (VarLookupCmb m1 m1, VarLookupCmb m1 m2) => VarLookupCmb [m1] [m2] where+ m1 |+> (m2:m2s) = (foldr1 (|+>) m1 |+> m2) : m2s class VarLookupBase m k v | m -> k v where varlookupEmpty :: m
uhc-util.cabal view
@@ -1,5 +1,5 @@ Name: uhc-util-Version: 0.1.5.1+Version: 0.1.5.2 cabal-version: >= 1.6 License: BSD3 Copyright: Utrecht University, Department of Information and Computing Sciences, Software Technology group