|
1 | 1 | {-# LANGUAGE CPP #-}
|
2 | 2 | {-# LANGUAGE RankNTypes #-}
|
3 | 3 |
|
| 4 | +{-# OPTIONS_GHC -fno-warn-name-shadowing #-} |
| 5 | + |
4 | 6 | -- | Internal module for utilities used in the implementation.
|
5 | 7 |
|
6 | 8 | module Utils (module Utils, module X) where
|
@@ -41,24 +43,22 @@ over l f o = runIdentity $ l (Identity . f) o
|
41 | 43 | #endif
|
42 | 44 |
|
43 | 45 | -- | After 'sort' or 'sortBy' the use of 'nub' or 'nubBy' can be replaced by 'norep' or 'norepBy'.
|
44 |
| -norep :: (Eq a) => [a]->[a] |
45 |
| -norep [] = [] |
46 |
| -norep x@[_] = x |
47 |
| -norep (a:bs@(c:cs)) | a==c = norep (a:cs) |
48 |
| - | otherwise = a:norep bs |
| 46 | +norep :: Eq a => [a] -> [a] |
| 47 | +norep = norepBy (==) |
49 | 48 |
|
50 | 49 | -- | After 'sort' or 'sortBy' the use of 'nub' or 'nubBy' can be replaced by 'norep' or 'norepBy'.
|
51 | 50 | norepBy :: (a -> a -> Bool) -> [a] -> [a]
|
52 |
| -norepBy _ [] = [] |
53 |
| -norepBy _ x@[_] = x |
54 |
| -norepBy eqF (a:bs@(c:cs)) | a `eqF` c = norepBy eqF (a:cs) |
55 |
| - | otherwise = a:norepBy eqF bs |
| 51 | +norepBy _ [] = [] |
| 52 | +norepBy eq (a:as) = loop a as |
| 53 | + where |
| 54 | + loop a [] = [a] |
| 55 | + loop a (b:bs) = (if a `eq` b then id else (a:)) $ loop b bs |
56 | 56 |
|
57 |
| -mapFst :: (Functor f) => (t -> t2) -> f (t, t1) -> f (t2, t1) |
58 |
| -mapFst f = fmap (\ (a,b) -> (f a,b)) |
| 57 | +mapFst :: Functor f => (t1 -> t2) -> f (t1, t) -> f (t2, t) |
| 58 | +mapFst f = fmap $ \ (a, b) -> (f a, b) |
59 | 59 |
|
60 |
| -mapSnd :: (Functor f) => (t1 -> t2) -> f (t, t1) -> f (t, t2) |
61 |
| -mapSnd f = fmap (\ (a,b) -> (a,f b)) |
| 60 | +mapSnd :: Functor f => (t1 -> t2) -> f (t, t1) -> f (t, t2) |
| 61 | +mapSnd f = fmap $ \ (a, b) -> (a, f b) |
62 | 62 |
|
63 | 63 | fst3 :: (a,b,c) -> a
|
64 | 64 | fst3 (x,_,_) = x
|
|
0 commit comments