|
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
|
@@ -44,24 +46,22 @@ over l f o = runIdentity $ l (Identity . f) o
|
44 | 46 | #endif
|
45 | 47 |
|
46 | 48 | -- | After 'sort' or 'sortBy' the use of 'nub' or 'nubBy' can be replaced by 'norep' or 'norepBy'.
|
47 |
| -norep :: (Eq a) => [a]->[a] |
48 |
| -norep [] = [] |
49 |
| -norep x@[_] = x |
50 |
| -norep (a:bs@(c:cs)) | a==c = norep (a:cs) |
51 |
| - | otherwise = a:norep bs |
| 49 | +norep :: Eq a => [a] -> [a] |
| 50 | +norep = norepBy (==) |
52 | 51 |
|
53 | 52 | -- | After 'sort' or 'sortBy' the use of 'nub' or 'nubBy' can be replaced by 'norep' or 'norepBy'.
|
54 | 53 | norepBy :: (a -> a -> Bool) -> [a] -> [a]
|
55 |
| -norepBy _ [] = [] |
56 |
| -norepBy _ x@[_] = x |
57 |
| -norepBy eqF (a:bs@(c:cs)) | a `eqF` c = norepBy eqF (a:cs) |
58 |
| - | otherwise = a:norepBy eqF bs |
| 54 | +norepBy _ [] = [] |
| 55 | +norepBy eq (a:as) = loop a as |
| 56 | + where |
| 57 | + loop a [] = [a] |
| 58 | + loop a (b:bs) = (if a `eq` b then id else (a:)) $ loop b bs |
59 | 59 |
|
60 |
| -mapFst :: (Functor f) => (t -> t2) -> f (t, t1) -> f (t2, t1) |
61 |
| -mapFst f = fmap (\ (a,b) -> (f a,b)) |
| 60 | +mapFst :: Functor f => (t1 -> t2) -> f (t1, t) -> f (t2, t) |
| 61 | +mapFst f = fmap $ \ (a, b) -> (f a, b) |
62 | 62 |
|
63 |
| -mapSnd :: (Functor f) => (t1 -> t2) -> f (t, t1) -> f (t, t2) |
64 |
| -mapSnd f = fmap (\ (a,b) -> (a,f b)) |
| 63 | +mapSnd :: Functor f => (t1 -> t2) -> f (t, t1) -> f (t, t2) |
| 64 | +mapSnd f = fmap $ \ (a, b) -> (a, f b) |
65 | 65 |
|
66 | 66 | fst3 :: (a,b,c) -> a
|
67 | 67 | fst3 (x,_,_) = x
|
|
0 commit comments