Skip to content

Commit eef7726

Browse files
authored
Disable deprecated things (#536)
Disable all deprecated functions by making them produce type errors when used. This is an experimental removal approach. It may or may not really be a good idea. The benefit is that unlike deprecation it *forces* people to make a change, and unlike immediate removal it tells them what change to make. With GHC 8.0 and above, the type errors are pretty. With earlier versions of GHC, they're gross. With a hypothetical non-GHC compiler, the functions are just removed.
1 parent 1a38677 commit eef7726

File tree

13 files changed

+194
-289
lines changed

13 files changed

+194
-289
lines changed

Data/IntMap.hs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#if !defined(TESTING) && defined(__GLASGOW_HASKELL__)
33
{-# LANGUAGE Safe #-}
44
#endif
5+
#ifdef __GLASGOW_HASKELL__
6+
{-# LANGUAGE DataKinds, FlexibleContexts #-}
7+
#endif
8+
#if __GLASGOW_HASKELL__ >= 800
9+
{-# LANGUAGE MonoLocalBinds #-}
10+
#endif
511

612
#include "containers.h"
713

@@ -54,43 +60,42 @@
5460

5561
module Data.IntMap
5662
( module Data.IntMap.Lazy
63+
#ifdef __GLASGOW_HASKELL__
64+
-- For GHC, we disable these, pending removal. For anything else,
65+
-- we just don't define them at all.
5766
, insertWith'
5867
, insertWithKey'
5968
, fold
6069
, foldWithKey
70+
#endif
6171
) where
6272

63-
import Prelude () -- hide foldr
64-
import qualified Data.IntMap.Strict as Strict
6573
import Data.IntMap.Lazy
6674

67-
-- | /O(log n)/. Same as 'insertWith', but the result of the combining function
68-
-- is evaluated to WHNF before inserted to the map.
75+
#ifdef __GLASGOW_HASKELL__
76+
import Utils.Containers.Internal.TypeError
6977

70-
{-# DEPRECATED insertWith' "As of version 0.5, replaced by 'Data.IntMap.Strict.insertWith'." #-}
71-
insertWith' :: (a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
72-
insertWith' = Strict.insertWith
78+
-- | This function is being removed and is no longer usable.
79+
-- Use 'Data.IntMap.Strict.insertWith'
80+
insertWith' :: Whoops "Data.IntMap.insertWith' is gone. Use Data.IntMap.Strict.insertWith."
81+
=> (a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
82+
insertWith' _ _ _ _ = undefined
7383

74-
-- | /O(log n)/. Same as 'insertWithKey', but the result of the combining
75-
-- function is evaluated to WHNF before inserted to the map.
84+
-- | This function is being removed and is no longer usable.
85+
-- Use 'Data.IntMap.Strict.insertWithKey'.
86+
insertWithKey' :: Whoops "Data.IntMap.insertWithKey' is gone. Use Data.IntMap.Strict.insertWithKey."
87+
=> (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
88+
insertWithKey' _ _ _ _ = undefined
7689

77-
{-# DEPRECATED insertWithKey' "As of version 0.5, replaced by 'Data.IntMap.Strict.insertWithKey'." #-}
78-
insertWithKey' :: (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a
79-
insertWithKey' = Strict.insertWithKey
90+
-- | This function is being removed and is no longer usable.
91+
-- Use 'Data.IntMap.Lazy.foldr'.
92+
fold :: Whoops "Data.IntMap.fold' is gone. Use Data.IntMap.foldr or Prelude.foldr."
93+
=> (a -> b -> b) -> b -> IntMap a -> b
94+
fold _ _ _ = undefined
8095

81-
-- | /O(n)/. Fold the values in the map using the given
82-
-- right-associative binary operator. This function is an equivalent
83-
-- of 'foldr' and is present for compatibility only.
84-
{-# DEPRECATED fold "As of version 0.5, replaced by 'foldr'." #-}
85-
fold :: (a -> b -> b) -> b -> IntMap a -> b
86-
fold = foldr
87-
{-# INLINE fold #-}
88-
89-
-- | /O(n)/. Fold the keys and values in the map using the given
90-
-- right-associative binary operator. This function is an equivalent
91-
-- of 'foldrWithKey' and is present for compatibility only.
92-
93-
{-# DEPRECATED foldWithKey "As of version 0.5, replaced by 'foldrWithKey'." #-}
94-
foldWithKey :: (Key -> a -> b -> b) -> b -> IntMap a -> b
95-
foldWithKey = foldrWithKey
96-
{-# INLINE foldWithKey #-}
96+
-- | This function is being removed and is no longer usable.
97+
-- Use 'foldrWithKey'.
98+
foldWithKey :: Whoops "Data.IntMap.foldWithKey is gone. Use foldrWithKey."
99+
=> (Key -> a -> b -> b) -> b -> IntMap a -> b
100+
foldWithKey _ _ _ = undefined
101+
#endif
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
{-# LANGUAGE CPP, FlexibleContexts, DataKinds, MonoLocalBinds #-}
2+
13
module Data.IntMap.Internal.DeprecatedDebug where
2-
import qualified Data.IntMap.Internal as IM
34
import Data.IntMap.Internal (IntMap)
45

5-
{-# DEPRECATED showTree, showTreeWith
6-
"These debugging functions will be removed from this module. They are available from Data.IntMap.Internal.Debug."
7-
#-}
6+
import Utils.Containers.Internal.TypeError
7+
88

9-
-- | /O(n)/. Show the tree that implements the map. The tree is shown
10-
-- in a compressed, hanging format.
11-
showTree :: Show a => IntMap a -> String
12-
showTree = IM.showTree
9+
-- | 'showTree' has moved to 'Data.IntMap.Internal.Debug.showTree'
10+
showTree :: Whoops "Data.IntMap.showTree has moved to Data.IntMap.Internal.Debug.showTree"
11+
=> IntMap a -> String
12+
showTree _ = undefined
1313

14-
{- | /O(n)/. The expression (@'showTreeWith' hang wide map@) shows
15-
the tree that implements the map. If @hang@ is
16-
'True', a /hanging/ tree is shown otherwise a rotated tree is shown. If
17-
@wide@ is 'True', an extra wide version is shown.
18-
-}
19-
showTreeWith :: Show a => Bool -> Bool -> IntMap a -> String
20-
showTreeWith = IM.showTreeWith
14+
-- | 'showTreeWith' has moved to 'Data.IntMap.Internal.Debug.showTreeWith'
15+
showTreeWith :: Whoops "Data.IntMap.showTreeWith has moved to Data.IntMap.Internal.Debug.showTreeWith"
16+
=> Bool -> Bool -> IntMap a -> String
17+
showTreeWith _ _ _ = undefined

Data/IntMap/Lazy.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,14 @@ module Data.IntMap.Lazy (
223223
, minViewWithKey
224224
, maxViewWithKey
225225

226+
#ifdef __GLASGOW_HASKELL__
226227
-- * Debugging
227228
, showTree
228229
, showTreeWith
230+
#endif
229231
) where
230232

231233
import Data.IntMap.Internal as IM hiding (showTree, showTreeWith)
234+
#ifdef __GLASGOW_HASKELL__
232235
import Data.IntMap.Internal.DeprecatedDebug
236+
#endif

Data/IntMap/Strict.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ module Data.IntMap.Strict (
242242
, minViewWithKey
243243
, maxViewWithKey
244244

245+
#ifdef __GLASGOW_HASKELL__
245246
-- * Debugging
246247
, showTree
247248
, showTreeWith
249+
#endif
248250
) where
249251

250252
import Prelude hiding (lookup,map,filter,foldr,foldl,null)
@@ -331,7 +333,9 @@ import Data.IntMap.Internal
331333
, unions
332334
, withoutKeys
333335
)
336+
#ifdef __GLASGOW_HASKELL__
334337
import Data.IntMap.Internal.DeprecatedDebug (showTree, showTreeWith)
338+
#endif
335339
import qualified Data.IntSet.Internal as IntSet
336340
import Utils.Containers.Internal.BitUtil
337341
import Utils.Containers.Internal.StrictPair

Data/Map.hs

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
{-# LANGUAGE Safe #-}
44
#endif
55

6+
#ifdef __GLASGOW_HASKELL__
7+
{-# LANGUAGE DataKinds, FlexibleContexts #-}
8+
#endif
9+
#if __GLASGOW_HASKELL__ >= 800
10+
{-# LANGUAGE MonoLocalBinds #-}
11+
#endif
12+
613
#include "containers.h"
714

815
-----------------------------------------------------------------------------
@@ -60,72 +67,48 @@
6067

6168
module Data.Map
6269
( module Data.Map.Lazy
70+
#ifdef __GLASGOW_HASKELL__
6371
, insertWith'
6472
, insertWithKey'
6573
, insertLookupWithKey'
6674
, fold
6775
, foldWithKey
76+
#endif
6877
) where
6978

70-
import Prelude hiding (foldr)
7179
import Data.Map.Lazy
72-
import qualified Data.Map.Strict as Strict
7380

74-
-- | /O(log n)/. Same as 'insertWith', but the value being inserted to the map is
75-
-- evaluated to WHNF beforehand.
76-
--
77-
-- For example, to update a counter:
78-
--
79-
-- > insertWith' (+) k 1 m
80-
--
81-
{-# DEPRECATED insertWith' "As of version 0.5, replaced by 'Data.Map.Strict.insertWith'." #-}
82-
insertWith' :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
83-
insertWith' = Strict.insertWith
84-
#if __GLASGOW_HASKELL__
85-
{-# INLINABLE insertWith' #-}
86-
#else
87-
{-# INLINE insertWith' #-}
88-
#endif
81+
#ifdef __GLASGOW_HASKELL__
82+
import Utils.Containers.Internal.TypeError
8983

90-
-- | /O(log n)/. Same as 'insertWithKey', but the value being inserted to the map is
91-
-- evaluated to WHNF beforehand.
92-
{-# DEPRECATED insertWithKey' "As of version 0.5, replaced by 'Data.Map.Strict.insertWithKey'." #-}
93-
insertWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a
94-
-- We do not reuse Data.Map.Strict.insertWithKey, because it is stricter -- it
95-
-- forces evaluation of the given value.
96-
insertWithKey' = Strict.insertWithKey
97-
#if __GLASGOW_HASKELL__
98-
{-# INLINABLE insertWithKey' #-}
99-
#else
100-
{-# INLINE insertWithKey' #-}
101-
#endif
84+
-- | This function is being removed and is no longer usable.
85+
-- Use 'Data.Map.Strict.insertWith'.
86+
insertWith' :: Whoops "Data.Map.insertWith' is gone. Use Data.Map.Strict.insertWith."
87+
=> (a -> a -> a) -> k -> a -> Map k a -> Map k a
88+
insertWith' _ _ _ _ = undefined
10289

103-
-- | /O(log n)/. Same as 'insertLookupWithKey', but the value being inserted to
104-
-- the map is evaluated to WHNF beforehand.
105-
{-# DEPRECATED insertLookupWithKey' "As of version 0.5, replaced by 'Data.Map.Strict.insertLookupWithKey'." #-}
106-
insertLookupWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a
90+
-- | This function is being removed and is no longer usable.
91+
-- Use 'Data.Map.Strict.insertWithKey'.
92+
insertWithKey' :: Whoops "Data.Map.insertWithKey' is gone. Use Data.Map.Strict.insertWithKey."
93+
=> (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a
94+
insertWithKey' _ _ _ _ = undefined
95+
96+
-- | This function is being removed and is no longer usable.
97+
-- Use 'Data.Map.Strict.insertLookupWithKey'.
98+
insertLookupWithKey' :: Whoops "Data.Map.insertLookupWithKey' is gone. Use Data.Map.Strict.insertLookupWithKey."
99+
=> (k -> a -> a -> a) -> k -> a -> Map k a
107100
-> (Maybe a, Map k a)
108-
-- We do not reuse Data.Map.Strict.insertLookupWithKey, because it is stricter -- it
109-
-- forces evaluation of the given value.
110-
insertLookupWithKey' = Strict.insertLookupWithKey
111-
#if __GLASGOW_HASKELL__
112-
{-# INLINABLE insertLookupWithKey' #-}
113-
#else
114-
{-# INLINE insertLookupWithKey' #-}
115-
#endif
101+
insertLookupWithKey' _ _ _ _ = undefined
116102

117-
-- | /O(n)/. Fold the values in the map using the given right-associative
118-
-- binary operator. This function is an equivalent of 'foldr' and is present
119-
-- for compatibility only.
120-
{-# DEPRECATED fold "As of version 0.5, replaced by 'foldr'." #-}
121-
fold :: (a -> b -> b) -> b -> Map k a -> b
122-
fold = foldr
123-
{-# INLINE fold #-}
103+
-- | This function is being removed and is no longer usable.
104+
-- Use 'foldr'.
105+
fold :: Whoops "Data.Map.fold is gone. Use foldr."
106+
=> (a -> b -> b) -> b -> Map k a -> b
107+
fold _ _ _ = undefined
124108

125-
-- | /O(n)/. Fold the keys and values in the map using the given right-associative
126-
-- binary operator. This function is an equivalent of 'foldrWithKey' and is present
127-
-- for compatibility only.
128-
{-# DEPRECATED foldWithKey "As of version 0.4, replaced by 'foldrWithKey'." #-}
129-
foldWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b
130-
foldWithKey = foldrWithKey
131-
{-# INLINE foldWithKey #-}
109+
-- | This function is being removed and is no longer usable.
110+
-- Use 'foldrWithKey'.
111+
foldWithKey :: Whoops "Data.Map.foldWithKey is gone. Use foldrWithKey."
112+
=> (k -> a -> b -> b) -> b -> Map k a -> b
113+
foldWithKey _ _ _ = undefined
114+
#endif
Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,29 @@
1-
{-# LANGUAGE CPP #-}
1+
{-# LANGUAGE CPP, FlexibleContexts, DataKinds #-}
2+
#if __GLASGOW_HASKELL__ >= 800
3+
{-# LANGUAGE MonoLocalBinds #-}
4+
#endif
5+
#if __GLASGOW_HASKELL__ < 710
6+
-- Why do we need this? Guess it doesn't matter; this is all
7+
-- going away soon.
8+
{-# LANGUAGE Trustworthy #-}
9+
#endif
210

311
#include "containers.h"
412

5-
-- | This module simply holds deprecated copies of functions from
13+
-- | This module simply holds disabled copies of functions from
614
-- Data.Map.Internal.Debug.
715
module Data.Map.Internal.DeprecatedShowTree where
816

9-
import qualified Data.Map.Internal.Debug as Debug
1017
import Data.Map.Internal (Map)
18+
import Utils.Containers.Internal.TypeError
1119

12-
-- | /O(n)/. Show the tree that implements the map. The tree is shown
13-
-- in a compressed, hanging format. See 'showTreeWith'.
14-
{-# DEPRECATED showTree "'showTree' is now in \"Data.Map.Internal.Debug\"" #-}
15-
showTree :: (Show k,Show a) => Map k a -> String
16-
showTree = Debug.showTree
20+
-- | This function has moved to 'Data.Map.Internal.Debug.showTree'.
21+
showTree :: Whoops "showTree has moved to Data.Map.Internal.Debug.showTree."
22+
=> Map k a -> String
23+
showTree _ = undefined
1724

18-
{- | /O(n)/. The expression (@'showTreeWith' showelem hang wide map@) shows
19-
the tree that implements the map. Elements are shown using the @showElem@ function. If @hang@ is
20-
'True', a /hanging/ tree is shown otherwise a rotated tree is shown. If
21-
@wide@ is 'True', an extra wide version is shown.
22-
23-
> Map> let t = fromDistinctAscList [(x,()) | x <- [1..5]]
24-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True False t
25-
> (4,())
26-
> +--(2,())
27-
> | +--(1,())
28-
> | +--(3,())
29-
> +--(5,())
30-
>
31-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True True t
32-
> (4,())
33-
> |
34-
> +--(2,())
35-
> | |
36-
> | +--(1,())
37-
> | |
38-
> | +--(3,())
39-
> |
40-
> +--(5,())
41-
>
42-
> Map> putStrLn $ showTreeWith (\k x -> show (k,x)) False True t
43-
> +--(5,())
44-
> |
45-
> (4,())
46-
> |
47-
> | +--(3,())
48-
> | |
49-
> +--(2,())
50-
> |
51-
> +--(1,())
52-
53-
-}
54-
{-# DEPRECATED showTreeWith "'showTreeWith' is now in \"Data.Map.Internal.Debug\"" #-}
55-
showTreeWith :: (k -> a -> String) -> Bool -> Bool -> Map k a -> String
56-
showTreeWith = Debug.showTreeWith
25+
-- | This function has moved to 'Data.Map.Internal.Debug.showTreeWith'.
26+
showTreeWith ::
27+
Whoops "showTreeWith has moved to Data.Map.Internal.Debug.showTreeWith."
28+
=> (k -> a -> String) -> Bool -> Bool -> Map k a -> String
29+
showTreeWith _ _ _ _ = undefined

Data/Map/Lazy.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ module Data.Map.Lazy (
262262
, maxViewWithKey
263263

264264
-- * Debugging
265+
#ifdef __GLASGOW_HASKELL__
265266
, showTree
266267
, showTreeWith
268+
#endif
267269
, valid
268270
) where
269271

Data/Map/Strict.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ module Data.Map.Strict
279279
, maxViewWithKey
280280

281281
-- * Debugging
282+
#ifdef __GLASGOW_HASKELL__
282283
, showTree
283284
, showTreeWith
285+
#endif
284286
, valid
285287
) where
286288

Data/Map/Strict/Internal.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,10 @@ module Data.Map.Strict.Internal
292292
, maxViewWithKey
293293

294294
-- * Debugging
295+
#if defined(__GLASGOW_HASKELL__)
295296
, showTree
296297
, showTreeWith
298+
#endif
297299
, valid
298300
) where
299301

@@ -397,7 +399,9 @@ import Data.Map.Internal
397399
, unions
398400
, withoutKeys )
399401

402+
#if defined(__GLASGOW_HASKELL__)
400403
import Data.Map.Internal.DeprecatedShowTree (showTree, showTreeWith)
404+
#endif
401405
import Data.Map.Internal.Debug (valid)
402406

403407
import Control.Applicative (Const (..), liftA3)

0 commit comments

Comments
 (0)