Changeset 12768
- Timestamp:
- 31.10.2009 15:21:50 (3 weeks ago)
- Files:
-
- 1 modified
-
trunk/Common/Utils.hs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Utils.hs
r12314 r12768 15 15 module Common.Utils 16 16 ( isSingleton 17 , replace 17 18 , hasMany 18 19 , number … … 47 48 import Control.Monad 48 49 50 -- | replace first (non-empty) sublist with second one in third argument list 51 replace :: Eq a => [a] -> [a] -> [a] -> [a] 52 replace sl r = case sl of 53 [] -> error "Common.Utils.replace: empty list" 54 _ -> replaceBy $ \ l@(hd : tl) -> case stripPrefix sl l of 55 Nothing -> ([hd], tl) 56 Just rt -> (r, rt) 57 58 replaceBy :: ([a] -> ([b], [a])) -> [a] -> [b] 59 replaceBy splt l = case l of 60 [] -> [] 61 _ -> let (ft, rt) = splt l in 62 ft ++ replaceBy splt rt 63 49 64 -- | add indices to a list starting from one 50 65 number :: [a] -> [(a, Int)]