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