Skip to content

Commit e622f78

Browse files
authored
Add Generic and Generic1 for Seq internals (#540)
Add `Generic` and `Generic1` instances for `Data.Sequence.Internal` types: `FingerTree`, `Node`, `Elem`, and `Digit`.
1 parent 630e93f commit e622f78

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

Data/Sequence/Internal.hs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,14 @@ data FingerTree a
932932
deriving Show
933933
#endif
934934

935+
#ifdef __GLASGOW_HASKELL__
936+
-- | @since 0.6.1
937+
deriving instance Generic1 FingerTree
938+
939+
-- | @since 0.6.1
940+
deriving instance Generic (FingerTree a)
941+
#endif
942+
935943
instance Sized a => Sized (FingerTree a) where
936944
{-# SPECIALIZE instance Sized (FingerTree (Elem a)) #-}
937945
{-# SPECIALIZE instance Sized (FingerTree (Node a)) #-}
@@ -1115,6 +1123,14 @@ data Digit a
11151123
deriving Show
11161124
#endif
11171125

1126+
#ifdef __GLASGOW_HASKELL__
1127+
-- | @since 0.6.1
1128+
deriving instance Generic1 Digit
1129+
1130+
-- | @since 0.6.1
1131+
deriving instance Generic (Digit a)
1132+
#endif
1133+
11181134
foldDigit :: (b -> b -> b) -> (a -> b) -> Digit a -> b
11191135
foldDigit _ f (One a) = f a
11201136
foldDigit (<+>) f (Two a b) = f a <+> f b
@@ -1208,6 +1224,14 @@ data Node a
12081224
deriving Show
12091225
#endif
12101226

1227+
#ifdef __GLASGOW_HASKELL__
1228+
-- | @since 0.6.1
1229+
deriving instance Generic1 Node
1230+
1231+
-- | @since 0.6.1
1232+
deriving instance Generic (Node a)
1233+
#endif
1234+
12111235
foldNode :: (b -> b -> b) -> (a -> b) -> Node a -> b
12121236
foldNode (<+>) f (Node2 _ a b) = f a <+> f b
12131237
foldNode (<+>) f (Node3 _ a b c) = f a <+> f b <+> f c
@@ -1269,6 +1293,14 @@ newtype Elem a = Elem { getElem :: a }
12691293
deriving Show
12701294
#endif
12711295

1296+
#ifdef __GLASGOW_HASKELL__
1297+
-- | @since 0.6.1
1298+
deriving instance Generic1 Elem
1299+
1300+
-- | @since 0.6.1
1301+
deriving instance Generic (Elem a)
1302+
#endif
1303+
12721304
instance Sized (Elem a) where
12731305
size _ = 1
12741306

@@ -1838,7 +1870,7 @@ data ViewL a
18381870
| a :< Seq a -- ^ leftmost element and the rest of the sequence
18391871
deriving (Eq, Ord, Show, Read)
18401872

1841-
#if __GLASGOW_HASKELL__
1873+
#ifdef __GLASGOW_HASKELL__
18421874
deriving instance Data a => Data (ViewL a)
18431875

18441876
-- | @since 0.5.8
@@ -1903,7 +1935,7 @@ data ViewR a
19031935
-- and the rightmost element
19041936
deriving (Eq, Ord, Show, Read)
19051937

1906-
#if __GLASGOW_HASKELL__
1938+
#ifdef __GLASGOW_HASKELL__
19071939
deriving instance Data a => Data (ViewR a)
19081940

19091941
-- | @since 0.5.8

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Add `Data.Containers.ListUtils` offering `nub`-like functions. (Thanks to
88
Gershom Bazerman for starting the process of writing these.)
99

10+
* Add `Generic` and `Generic1` instances for key `Data.Sequence.Internal` types:
11+
`Node`, `Digit`, `Elem`, and `FingerTree`.
12+
1013
### Death of deprecated functions
1114

1215
The following functions have been disabled. As an experiment

0 commit comments

Comments
 (0)