3
3
{-# LANGUAGE KindSignatures #-}
4
4
{-# LANGUAGE PatternSynonyms #-}
5
5
{-# LANGUAGE RoleAnnotations #-}
6
+ #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
6
7
{-# LANGUAGE Trustworthy #-}
8
+ #else
9
+ {-# LANGUAGE Safe #-}
10
+ #endif
7
11
{-# LANGUAGE TypeOperators #-}
8
12
{-# LANGUAGE ViewPatterns #-}
9
13
@@ -33,8 +37,10 @@ module Data.Sequence.Internal.Depth
33
37
, Depth2_ (Bottom2 , Deeper2 )
34
38
) where
35
39
40
+ #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
36
41
import Data.Kind (Type )
37
42
import Unsafe.Coerce (unsafeCoerce )
43
+ #endif
38
44
39
45
-- @Depth_@ is an optimized representation of the following GADT:
40
46
--
@@ -55,6 +61,15 @@ import Unsafe.Coerce (unsafeCoerce)
55
61
-- arithmetic overflow on 64-bit systems requires somewhat absurdly long
56
62
-- computations on sequences constructed with extensive amounts of internal
57
63
-- sharing (e.g., using the '*>' operator repeatedly).
64
+ #if !defined(MIN_VERSION_GLASGOW_HASKELL) || !MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
65
+ -- Old versions of GHC would crash out in all sorts of weird ways with the fancy version,
66
+ -- so we give a totally plain version here. We also use the plain one for MicroHS, for
67
+ -- now, because I don't know what it wants.
68
+ data Depth_ node a t where
69
+ Bottom :: Depth_ node a a
70
+ Deeper :: ! (Depth_ node a t ) -> Depth_ node a (node t )
71
+
72
+ #else
58
73
newtype Depth_ (node :: Type -> Type ) (a :: Type ) (t :: Type )
59
74
= Depth_ Word
60
75
type role Depth_ nominal nominal nominal
@@ -64,9 +79,7 @@ pattern Bottom :: () => t ~ a => Depth_ node a t
64
79
pattern Bottom <- (checkBottom -> AtBottom )
65
80
where
66
81
Bottom = Depth_ 0
67
- #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
68
82
{-# INLINE Bottom #-}
69
- #endif
70
83
71
84
-- | The depth is non-zero.
72
85
pattern Deeper :: () => t ~ node t' => Depth_ node a t' -> Depth_ node a t
@@ -75,9 +88,7 @@ pattern Deeper d <- (checkBottom -> NotBottom d)
75
88
Deeper (Depth_ d)
76
89
| d == maxBound = error " Depth overflow"
77
90
| otherwise = Depth_ (d + 1 )
78
- #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
79
91
{-# INLINE Deeper #-}
80
- #endif
81
92
82
93
{-# COMPLETE Bottom, Deeper #-}
83
94
@@ -88,20 +99,22 @@ data CheckedBottom node a t where
88
99
checkBottom :: Depth_ node a t -> CheckedBottom node a t
89
100
checkBottom (Depth_ 0 ) = unsafeCoerce AtBottom
90
101
checkBottom (Depth_ d) = unsafeCoerce (NotBottom (Depth_ (d - 1 )))
91
- #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
92
102
{-# INLINE checkBottom #-}
93
- #else
94
- {-# NOINLINE checkBottom #-}
95
- #endif
96
103
104
+ #endif
97
105
98
106
-- | A version of 'Depth_' for implementing traversals. Conceptually,
99
107
--
100
108
-- @
101
109
-- data Depth2_ node a t b u where
102
110
-- Bottom2 :: Depth2_ node a a b b
103
- -- Deeper2 :: !(Depth2_ node a t b u) -> Depth_ node a (node t) b (node u)
111
+ -- Deeper2 :: !(Depth2_ node a t b u) -> Depth2_ node a (node t) b (node u)
104
112
-- @
113
+ #if !defined(MIN_VERSION_GLASGOW_HASKELL) || !MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
114
+ data Depth2_ node a t b u where
115
+ Bottom2 :: Depth2_ node a a b b
116
+ Deeper2 :: ! (Depth2_ node a t b u ) -> Depth2_ node a (node t ) b (node u )
117
+ #else
105
118
newtype Depth2_ (node :: Type -> Type ) (a :: Type ) (t :: Type ) (b :: Type ) (u :: Type )
106
119
= Depth2_ Word
107
120
type role Depth2_ nominal nominal nominal nominal nominal
@@ -111,9 +124,7 @@ pattern Bottom2 :: () => (t ~ a, u ~ b) => Depth2_ node a t b u
111
124
pattern Bottom2 <- (checkBottom2 -> AtBottom2 )
112
125
where
113
126
Bottom2 = Depth2_ 0
114
- #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
115
127
{-# INLINE Bottom2 #-}
116
- #endif
117
128
118
129
-- | The depth is non-zero.
119
130
pattern Deeper2 :: () => (t ~ node t' , u ~ node u' ) => Depth2_ node a t' b u' -> Depth2_ node a t b u
@@ -122,9 +133,7 @@ pattern Deeper2 d <- (checkBottom2 -> NotBottom2 d)
122
133
Deeper2 (Depth2_ d)
123
134
| d == maxBound = error " Depth2 overflow"
124
135
| otherwise = Depth2_ (d + 1 )
125
- #if defined(MIN_VERSION_GLASGOW_HASKELL) && MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
126
136
{-# INLINE Deeper2 #-}
127
- #endif
128
137
129
138
{-# COMPLETE Bottom2, Deeper2 #-}
130
139
@@ -135,8 +144,5 @@ data CheckedBottom2 node a t b u where
135
144
checkBottom2 :: Depth2_ node a t b u -> CheckedBottom2 node a t b u
136
145
checkBottom2 (Depth2_ 0 ) = unsafeCoerce AtBottom2
137
146
checkBottom2 (Depth2_ d) = unsafeCoerce (NotBottom2 (Depth2_ (d - 1 )))
138
- #if MIN_VERSION_GLASGOW_HASKELL(9,2,0,0)
139
147
{-# INLINE checkBottom2 #-}
140
- #else
141
- {-# NOINLINE checkBottom2 #-}
142
148
#endif
0 commit comments