|
1 | 1 | {-# LANGUAGE CPP #-}
|
| 2 | +#if __GLASGOW_HASKELL__ >= 708 |
| 3 | +#define DEFINE_PATTERN_SYNONYMS 1 |
| 4 | +#endif |
2 | 5 | #if __GLASGOW_HASKELL__
|
3 | 6 | {-# LANGUAGE DeriveDataTypeable #-}
|
4 | 7 | {-# LANGUAGE StandaloneDeriving #-}
|
|
10 | 13 | #if __GLASGOW_HASKELL__ >= 708
|
11 | 14 | {-# LANGUAGE TypeFamilies #-}
|
12 | 15 | #endif
|
| 16 | +#ifdef DEFINE_PATTERN_SYNONYMS |
| 17 | +{-# LANGUAGE PatternSynonyms #-} |
| 18 | +{-# LANGUAGE ViewPatterns #-} |
| 19 | +#endif |
13 | 20 |
|
14 | 21 | #include "containers.h"
|
15 | 22 |
|
|
56 | 63 | -----------------------------------------------------------------------------
|
57 | 64 |
|
58 | 65 | module Data.Sequence (
|
59 |
| -#if !defined(TESTING) |
60 |
| - Seq, |
| 66 | +#if defined(TESTING) |
| 67 | + Elem(..), FingerTree(..), Node(..), Digit(..), |
| 68 | +#if __GLASGOW_HASKELL__ >= 800 |
| 69 | + Seq (.., Empty, (:<|), (:|>)), |
| 70 | +#else |
| 71 | + Seq (..), |
| 72 | +#endif |
| 73 | + |
| 74 | +#elif __GLASGOW_HASKELL__ >= 800 |
| 75 | + Seq (Empty, (:<|), (:|>)), |
61 | 76 | #else
|
62 |
| - Seq(..), Elem(..), FingerTree(..), Node(..), Digit(..), |
| 77 | + Seq, |
| 78 | +#if defined(DEFINE_PATTERN_SYNONYMS) |
| 79 | + -- * Pattern synonyms |
| 80 | + pattern Empty, -- :: Seq a |
| 81 | + pattern (:<|), -- :: a -> Seq a -> Seq a |
| 82 | + pattern (:|>), -- :: Seq a -> a -> Seq a |
| 83 | +#endif |
63 | 84 | #endif
|
64 | 85 | -- * Construction
|
65 | 86 | empty, -- :: Seq a
|
@@ -220,6 +241,45 @@ infixr 5 ><
|
220 | 241 | infixr 5 <|, :<
|
221 | 242 | infixl 5 |>, :>
|
222 | 243 |
|
| 244 | +#ifdef DEFINE_PATTERN_SYNONYMS |
| 245 | +infixr 5 :<| |
| 246 | +infixl 5 :|> |
| 247 | + |
| 248 | +-- TODO: Once GHC implements some way to prevent non-exhaustive |
| 249 | +-- pattern match warnings for pattern synonyms, we should be |
| 250 | +-- sure to take advantage of that. |
| 251 | + |
| 252 | +-- Unfortunately, there's some extra noise here because |
| 253 | +-- pattern synonyms could not have signatures until 7.10, |
| 254 | +-- but 8.0 at least will warn if they're missing. |
| 255 | +#if __GLASGOW_HASKELL__ >= 710 |
| 256 | +pattern Empty :: Seq a |
| 257 | +#endif |
| 258 | +pattern Empty = Seq EmptyT |
| 259 | + |
| 260 | +-- Non-trivial bidirectional pattern synonyms are only |
| 261 | +-- available in GHC >= 7.10. In earlier versions, these |
| 262 | +-- can be used to match, but not to construct. |
| 263 | + |
| 264 | +#if __GLASGOW_HASKELL__ >= 710 |
| 265 | +pattern (:<|) :: a -> Seq a -> Seq a |
| 266 | +#endif |
| 267 | +pattern x :<| xs <- (viewl -> x :< xs) |
| 268 | +#if __GLASGOW_HASKELL__ >= 710 |
| 269 | + where |
| 270 | + x :<| xs = x <| xs |
| 271 | +#endif |
| 272 | + |
| 273 | +#if __GLASGOW_HASKELL__ >= 710 |
| 274 | +pattern (:|>) :: Seq a -> a -> Seq a |
| 275 | +#endif |
| 276 | +pattern xs :|> x <- (viewr -> xs :> x) |
| 277 | +#if __GLASGOW_HASKELL__ >= 710 |
| 278 | + where |
| 279 | + xs :|> x = xs |> x |
| 280 | +#endif |
| 281 | +#endif |
| 282 | + |
223 | 283 | class Sized a where
|
224 | 284 | size :: a -> Int
|
225 | 285 |
|
|
0 commit comments