|
7 | 7 | {-# LANGUAGE DeriveLift #-} |
8 | 8 | {-# LANGUAGE StandaloneDeriving #-} |
9 | 9 | {-# LANGUAGE FlexibleInstances #-} |
| 10 | +{-# LANGUAGE InstanceSigs #-} |
10 | 11 | {-# LANGUAGE ScopedTypeVariables #-} |
11 | 12 | {-# LANGUAGE TemplateHaskellQuotes #-} |
12 | 13 | {-# LANGUAGE Trustworthy #-} |
@@ -244,8 +245,6 @@ import qualified Data.List |
244 | 245 | import Data.Array (Ix, Array) |
245 | 246 | import qualified Data.Array |
246 | 247 |
|
247 | | -import Utils.Containers.Internal.Coercions ((.#), (.^#)) |
248 | | - |
249 | 248 | import Data.Functor.Identity (Identity(..)) |
250 | 249 |
|
251 | 250 | import Utils.Containers.Internal.StrictPair (StrictPair (..), toPair) |
@@ -395,33 +394,45 @@ fmapSeq f (Seq xs) = Seq (fmap (fmap f) xs) |
395 | 394 | #-} |
396 | 395 | #endif |
397 | 396 |
|
398 | | -getSeq :: Seq a -> FingerTree (Elem a) |
399 | | -getSeq (Seq xs) = xs |
400 | | - |
401 | 397 | instance Foldable Seq where |
402 | | - foldMap f = foldMap (f .# getElem) .# getSeq |
403 | | - foldr f z = foldr (f .# getElem) z .# getSeq |
404 | | - foldl f z = foldl (f .^# getElem) z .# getSeq |
| 398 | +#ifdef __GLASGOW_HASKELL__ |
| 399 | + foldMap :: forall m a. Monoid m => (a -> m) -> Seq a -> m |
| 400 | + foldMap = coerce (foldMap :: (Elem a -> m) -> FingerTree (Elem a) -> m) |
405 | 401 |
|
406 | | -#if __GLASGOW_HASKELL__ |
407 | | - {-# INLINABLE foldMap #-} |
408 | | - {-# INLINABLE foldr #-} |
409 | | - {-# INLINABLE foldl #-} |
410 | | -#endif |
| 402 | + foldr :: forall a b. (a -> b -> b) -> b -> Seq a -> b |
| 403 | + foldr = coerce (foldr :: (Elem a -> b -> b) -> b -> FingerTree (Elem a) -> b) |
411 | 404 |
|
412 | | - foldr' f z = foldr' (f .# getElem) z .# getSeq |
413 | | - foldl' f z = foldl' (f .^# getElem) z .# getSeq |
| 405 | + foldl :: forall b a. (b -> a -> b) -> b -> Seq a -> b |
| 406 | + foldl = coerce (foldl :: (b -> Elem a -> b) -> b -> FingerTree (Elem a) -> b) |
414 | 407 |
|
415 | | -#if __GLASGOW_HASKELL__ |
416 | | - {-# INLINABLE foldr' #-} |
417 | | - {-# INLINABLE foldl' #-} |
418 | | -#endif |
| 408 | + foldr' :: forall a b. (a -> b -> b) -> b -> Seq a -> b |
| 409 | + foldr' = coerce (foldr' :: (Elem a -> b -> b) -> b -> FingerTree (Elem a) -> b) |
| 410 | + |
| 411 | + foldl' :: forall b a. (b -> a -> b) -> b -> Seq a -> b |
| 412 | + foldl' = coerce (foldl' :: (b -> Elem a -> b) -> b -> FingerTree (Elem a) -> b) |
| 413 | + |
| 414 | + foldr1 :: forall a. (a -> a -> a) -> Seq a -> a |
| 415 | + foldr1 = coerce (foldr1 :: (Elem a -> Elem a -> Elem a) -> FingerTree (Elem a) -> Elem a) |
| 416 | + |
| 417 | + foldl1 :: forall a. (a -> a -> a) -> Seq a -> a |
| 418 | + foldl1 = coerce (foldl1 :: (Elem a -> Elem a -> Elem a) -> FingerTree (Elem a) -> Elem a) |
| 419 | +#else |
| 420 | + foldMap f (Seq xs) = foldMap (f . getElem) xs |
| 421 | + |
| 422 | + foldr f z (Seq xs) = foldr (f . getElem) z xs |
| 423 | + |
| 424 | + foldl f z (Seq xs) = foldl (\z' x -> f z' (getElem x)) z xs |
| 425 | + |
| 426 | + foldr' f z (Seq xs) = foldr' (f . getElem) z xs |
| 427 | + |
| 428 | + foldl' f z (Seq xs) = foldl' (\z' x -> f z' (getElem x)) z xs |
419 | 429 |
|
420 | 430 | foldr1 f (Seq xs) = getElem (foldr1 f' xs) |
421 | 431 | where f' (Elem x) (Elem y) = Elem (f x y) |
422 | 432 |
|
423 | 433 | foldl1 f (Seq xs) = getElem (foldl1 f' xs) |
424 | 434 | where f' (Elem x) (Elem y) = Elem (f x y) |
| 435 | +#endif |
425 | 436 |
|
426 | 437 | length = length |
427 | 438 | {-# INLINE length #-} |
|
0 commit comments