Skip to content

Commit 273578b

Browse files
authored
Merge pull request #334 from treeowl/expose-patsyms
Actually expose Data.Sequence pattern synonyms
2 parents b5b9d1e + 5f316c4 commit 273578b

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

Data/Map/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ fromAscList xs
33223322
(x:xx) -> combineEq' x xx
33233323

33243324
combineEq' z [] = [z]
3325-
combineEq' z@(kz,zz) (x@(kx,xx):xs')
3325+
combineEq' z@(kz,_) (x@(kx,xx):xs')
33263326
| kx==kz = combineEq' (kx,xx) xs'
33273327
| otherwise = z:combineEq' x xs'
33283328
#if __GLASGOW_HASKELL__
@@ -3348,7 +3348,7 @@ fromDescList xs = fromDistinctDescList (combineEq xs)
33483348
(x:xx) -> combineEq' x xx
33493349

33503350
combineEq' z [] = [z]
3351-
combineEq' z@(kz,zz) (x@(kx,xx):xs')
3351+
combineEq' z@(kz,_) (x@(kx,xx):xs')
33523352
| kx==kz = combineEq' (kx,xx) xs'
33533353
| otherwise = z:combineEq' x xs'
33543354
#if __GLASGOW_HASKELL__

Data/Sequence/Internal.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{-# LANGUAGE CPP #-}
2+
#include "containers.h"
23
{-# LANGUAGE BangPatterns #-}
3-
#if __GLASGOW_HASKELL__ >= 800
4-
#define DEFINE_PATTERN_SYNONYMS 1
5-
#endif
64
#if __GLASGOW_HASKELL__
75
{-# LANGUAGE DeriveDataTypeable #-}
86
{-# LANGUAGE StandaloneDeriving #-}
@@ -23,8 +21,6 @@
2321
{-# LANGUAGE ViewPatterns #-}
2422
#endif
2523

26-
#include "containers.h"
27-
2824
-----------------------------------------------------------------------------
2925
-- |
3026
-- Module : Data.Sequence.Internal

include/containers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#define INSTANCE_TYPEABLE2(tycon)
3030
#endif
3131

32+
#if __GLASGOW_HASKELL__ >= 800
33+
#define DEFINE_PATTERN_SYNONYMS 1
34+
#endif
35+
3236
/*
3337
* We use cabal-generated MIN_VERSION_base to adapt to changes of base.
3438
* Nevertheless, as a convenience, we also allow compiling without cabal by

tests/seq-properties.hs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE PatternGuards #-}
3+
14
import Data.Sequence.Internal
5+
( Sized (..)
6+
, Seq (Seq)
7+
, FingerTree(..)
8+
, Node(..)
9+
, Elem(..)
10+
, Digit (..)
11+
, node2
12+
, node3
13+
, deep )
14+
15+
import Data.Sequence
216

317
import Control.Applicative (Applicative(..))
418
import Control.Arrow ((***))
@@ -18,6 +32,9 @@ import qualified Prelude
1832
import qualified Data.List
1933
import Test.QuickCheck hiding ((><))
2034
import Test.QuickCheck.Poly
35+
#if __GLASGOW_HASKELL__ >= 800
36+
import Test.QuickCheck.Property
37+
#endif
2138
import Test.QuickCheck.Function
2239
import Test.Framework
2340
import Test.Framework.Providers.QuickCheck2
@@ -109,6 +126,14 @@ main = defaultMain
109126
, testProperty "cycleTaking" prop_cycleTaking
110127
, testProperty "intersperse" prop_intersperse
111128
, testProperty ">>=" prop_bind
129+
#if __GLASGOW_HASKELL__ >= 800
130+
, testProperty "Empty pattern" prop_empty_pat
131+
, testProperty "Empty constructor" prop_empty_con
132+
, testProperty "Left view pattern" prop_viewl_pat
133+
, testProperty "Left view constructor" prop_viewl_con
134+
, testProperty "Right view pattern" prop_viewr_pat
135+
, testProperty "Right view constructor" prop_viewr_con
136+
#endif
112137
]
113138

114139
------------------------------------------------------------------------
@@ -679,6 +704,33 @@ prop_cycleTaking :: Int -> Seq A -> Property
679704
prop_cycleTaking n xs =
680705
(n <= 0 || not (null xs)) ==> toList' (cycleTaking n xs) ~= Data.List.take n (Data.List.cycle (toList xs))
681706

707+
#if __GLASGOW_HASKELL__ >= 800
708+
prop_empty_pat :: Seq A -> Bool
709+
prop_empty_pat xs@Empty = null xs
710+
prop_empty_pat xs = not (null xs)
711+
712+
prop_empty_con :: Bool
713+
prop_empty_con = null Empty
714+
715+
prop_viewl_pat :: Seq A -> Property
716+
prop_viewl_pat xs@(y :<| ys)
717+
| z :< zs <- viewl xs = y === z .&&. ys === zs
718+
| otherwise = property failed
719+
prop_viewl_pat xs = property . liftBool $ null xs
720+
721+
prop_viewl_con :: A -> Seq A -> Property
722+
prop_viewl_con x xs = x :<| xs === x <| xs
723+
724+
prop_viewr_pat :: Seq A -> Property
725+
prop_viewr_pat xs@(ys :|> y)
726+
| zs :> z <- viewr xs = y === z .&&. ys === zs
727+
| otherwise = property failed
728+
prop_viewr_pat xs = property . liftBool $ null xs
729+
730+
prop_viewr_con :: Seq A -> A -> Property
731+
prop_viewr_con xs x = xs :|> x === xs |> x
732+
#endif
733+
682734
-- Monad operations
683735

684736
prop_bind :: Seq A -> Fun A (Seq B) -> Bool

0 commit comments

Comments
 (0)