Skip to content

Commit 809a996

Browse files
authored
Merge pull request #42 from haskellari/polykinds-deepseq
Make GNFData PolyKinded
2 parents 5e974de + 6286d44 commit 809a996

File tree

6 files changed

+115
-10
lines changed

6 files changed

+115
-10
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.0.3
2+
3+
- Make `GNFData` PolyKinded.
4+
- Add `GNFData ((:~:) a)` and `GNFData TypeRep` instances
5+
16
# 1.0.2
27

38
- Explicitly mark `Data.Some` as `Safe`.

some.cabal

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: some
2-
version: 1.0.2
2+
version: 1.0.3
33
stability: provisional
44
cabal-version: >=1.10
55
build-type: Simple
@@ -60,11 +60,12 @@ library
6060
if flag(newtype-unsafe)
6161
cpp-options: -DSOME_NEWTYPE
6262

63+
-- main module
64+
exposed-modules: Data.Some
6365
exposed-modules:
6466
Data.GADT.Compare
6567
Data.GADT.DeepSeq
6668
Data.GADT.Show
67-
Data.Some
6869
Data.Some.Church
6970
Data.Some.GADT
7071
Data.Some.Newtype
@@ -83,11 +84,14 @@ library
8384
, transformers >=0.3 && <0.6
8485
, transformers-compat >=0.6 && <0.7
8586

86-
if impl(ghc >= 9.0)
87+
if impl(ghc >=9.0)
8788
-- these flags may abort compilation with GHC-8.10
8889
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295
8990
ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode
9091

92+
if impl(ghc >=9.1)
93+
ghc-options: -Wmissing-kind-signatures
94+
9195
test-suite hkd-example
9296
default-language: Haskell2010
9397
type: exitcode-stdio-1.0

src/Data/GADT/DeepSeq.hs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{-# LANGUAGE CPP #-}
2-
#if __GLASGOW_HASKELL__ >= 704
2+
{-# LANGUAGE GADTs #-}
3+
#if __GLASGOW_HASKELL__ >= 706
4+
{-# LANGUAGE PolyKinds #-}
5+
#endif
6+
#if __GLASGOW_HASKELL__ >= 810
7+
{-# LANGUAGE StandaloneKindSignatures #-}
8+
#endif
9+
#if (__GLASGOW_HASKELL__ >= 704 && __GLASGOW_HASKELL__ < 707) || __GLASGOW_HASKELL__ >= 801
310
{-# LANGUAGE Safe #-}
411
#elif __GLASGOW_HASKELL__ >= 702
512
{-# LANGUAGE Trustworthy #-}
@@ -10,6 +17,19 @@ module Data.GADT.DeepSeq (
1017

1118
import Data.Functor.Product (Product (..))
1219
import Data.Functor.Sum (Sum (..))
20+
import Data.Type.Equality ((:~:) (..))
21+
22+
#if MIN_VERSION_base(4,10,0)
23+
import qualified Type.Reflection as TR
24+
#endif
25+
26+
#if __GLASGOW_HASKELL__ >= 810
27+
import Data.Kind (Type, Constraint)
28+
#endif
29+
30+
#if __GLASGOW_HASKELL__ >= 810
31+
type GNFData :: (k -> Type) -> Constraint
32+
#endif
1333

1434
class GNFData f where
1535
grnf :: f a -> ()
@@ -20,3 +40,13 @@ instance (GNFData a, GNFData b) => GNFData (Product a b) where
2040
instance (GNFData a, GNFData b) => GNFData (Sum a b) where
2141
grnf (InL x) = grnf x
2242
grnf (InR y) = grnf y
43+
44+
-- | @since 1.0.3
45+
instance GNFData ((:~:) a) where
46+
grnf Refl = ()
47+
48+
#if MIN_VERSION_base(4,10,0)
49+
-- | @since 1.0.3
50+
instance GNFData TR.TypeRep where
51+
grnf = TR.rnfTypeRep
52+
#endif

src/Data/GADT/Internal.hs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
#if __GLASGOW_HASKELL__ >= 706
88
{-# LANGUAGE PolyKinds #-}
99
#endif
10-
#if __GLASGOW_HASKELL__ >= 704
11-
#define GHC __GLASGOW_HASKELL__
12-
#if (GHC >= 704 && GHC <707) || GHC >= 801
10+
#if __GLASGOW_HASKELL__ >= 708
11+
{-# LANGUAGE RoleAnnotations #-}
12+
#endif
13+
#if __GLASGOW_HASKELL__ >= 810
14+
{-# LANGUAGE StandaloneKindSignatures #-}
15+
#endif
16+
#if (__GLASGOW_HASKELL__ >= 704 && __GLASGOW_HASKELL__ < 707) || __GLASGOW_HASKELL__ >= 801
1317
{-# LANGUAGE Safe #-}
14-
#else
18+
#elif __GLASGOW_HASKELL__ >= 702
1519
{-# LANGUAGE Trustworthy #-}
1620
#endif
17-
#undef GHC
18-
#endif
1921
module Data.GADT.Internal where
2022

2123
import Control.Applicative (Applicative (..))
@@ -35,6 +37,10 @@ import Data.Type.Equality (testEquality)
3537
import qualified Type.Reflection as TR
3638
#endif
3739

40+
#if __GLASGOW_HASKELL__ >= 810
41+
import Data.Kind (Type, Constraint)
42+
#endif
43+
3844
-- $setup
3945
-- >>> :set -XKindSignatures -XGADTs
4046

@@ -43,6 +49,9 @@ import qualified Type.Reflection as TR
4349
-- to write (or derive) an @instance Show (T a)@, and then simply say:
4450
--
4551
-- > instance GShow t where gshowsPrec = showsPrec
52+
#if __GLASGOW_HASKELL__ >= 810
53+
type GShow :: (k -> Type) -> Constraint
54+
#endif
4655
class GShow t where
4756
gshowsPrec :: Int -> t a -> ShowS
4857

@@ -79,6 +88,9 @@ instance (GShow a, GShow b) => GShow (Product a b) where
7988

8089
-- |@GReadS t@ is equivalent to @ReadS (forall b. (forall a. t a -> b) -> b)@, which is
8190
-- in turn equivalent to @ReadS (Exists t)@ (with @data Exists t where Exists :: t a -> Exists t@)
91+
#if __GLASGOW_HASKELL__ >= 810
92+
type GReadS :: (k -> Type) -> Type
93+
#endif
8294
type GReadS t = String -> [(Some t, String)]
8395

8496
getGReadResult :: Some tag -> (forall a. tag a -> b) -> b
@@ -90,6 +102,9 @@ mkGReadResult = mkSome
90102
-- |'Read'-like class for 1-type-parameter GADTs. Unlike 'GShow', this one cannot be
91103
-- mechanically derived from a 'Read' instance because 'greadsPrec' must choose the phantom
92104
-- type based on the 'String' being parsed.
105+
#if __GLASGOW_HASKELL__ >= 810
106+
type GRead :: (k -> Type) -> Constraint
107+
#endif
93108
class GRead t where
94109
greadsPrec :: Int -> GReadS t
95110

@@ -139,6 +154,9 @@ instance (GRead a, GRead b) => GRead (Sum a b) where
139154
-- |A class for type-contexts which contain enough information
140155
-- to (at least in some cases) decide the equality of types
141156
-- occurring within them.
157+
#if __GLASGOW_HASKELL__ >= 810
158+
type GEq :: (k -> Type) -> Constraint
159+
#endif
142160
class GEq f where
143161
-- |Produce a witness of type-equality, if one exists.
144162
--
@@ -219,6 +237,9 @@ instance GEq TR.TypeRep where
219237
-- |A type for the result of comparing GADT constructors; the type parameters
220238
-- of the GADT values being compared are included so that in the case where
221239
-- they are equal their parameter types can be unified.
240+
#if __GLASGOW_HASKELL__ >= 810
241+
type GOrdering :: k -> k -> Type
242+
#endif
222243
data GOrdering a b where
223244
GLT :: GOrdering a b
224245
GEQ :: GOrdering t t
@@ -259,6 +280,9 @@ instance GRead (GOrdering a) where
259280

260281
-- |Type class for comparable GADT-like structures. When 2 things are equal,
261282
-- must return a witness that their parameter types are equal as well ('GEQ').
283+
#if __GLASGOW_HASKELL__ >= 810
284+
type GCompare :: (k -> Type) -> Constraint
285+
#endif
262286
class GEq f => GCompare f where
263287
gcompare :: f a -> f b -> GOrdering a b
264288

@@ -343,11 +367,18 @@ instance (GCompare a, GCompare b) => GCompare (Product a b) where
343367
-- >>> read "mkSome TagInt" :: Some Tag
344368
-- mkSome TagInt
345369
--
370+
#if __GLASGOW_HASKELL__ >= 810
371+
type Some :: (k -> Type) -> Type
372+
#endif
346373
newtype Some tag = S
347374
{ -- | Eliminator.
348375
withSome :: forall r. (forall a. tag a -> r) -> r
349376
}
350377

378+
#if __GLASGOW_HASKELL__ >= 708
379+
type role Some representational
380+
#endif
381+
351382
-- | Constructor.
352383
mkSome :: tag a -> Some tag
353384
mkSome t = S (\f -> f t)

src/Data/Some/GADT.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#if __GLASGOW_HASKELL__ >= 706
55
{-# LANGUAGE PolyKinds #-}
66
#endif
7+
#if __GLASGOW_HASKELL__ >= 708
8+
{-# LANGUAGE RoleAnnotations #-}
9+
#endif
10+
#if __GLASGOW_HASKELL__ >= 810
11+
{-# LANGUAGE StandaloneKindSignatures #-}
12+
#endif
713
#if __GLASGOW_HASKELL__ >= 704
814
{-# LANGUAGE Safe #-}
915
#elif __GLASGOW_HASKELL__ >= 702
@@ -24,10 +30,15 @@ import Control.DeepSeq (NFData (..))
2430
import Data.Monoid (Monoid (..))
2531
import Data.Semigroup (Semigroup (..))
2632

33+
#if __GLASGOW_HASKELL__ >= 810
34+
import Data.Kind (Type)
35+
#endif
36+
2737
import Data.GADT.Compare
2838
import Data.GADT.DeepSeq
2939
import Data.GADT.Show
3040

41+
3142
-- $setup
3243
-- >>> :set -XKindSignatures -XGADTs
3344

@@ -73,9 +84,16 @@ import Data.GADT.Show
7384
-- >>> read "mkSome TagInt" :: Some Tag
7485
-- Some TagInt
7586
--
87+
#if __GLASGOW_HASKELL__ >= 810
88+
type Some :: (k -> Type) -> Type
89+
#endif
7690
data Some tag where
7791
Some :: tag a -> Some tag
7892

93+
#if __GLASGOW_HASKELL__ >= 708
94+
type role Some representational
95+
#endif
96+
7997
-- | Constructor.
8098
mkSome :: tag a -> Some tag
8199
mkSome = Some

src/Data/Some/Newtype.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
#if __GLASGOW_HASKELL__ >= 801
55
{-# LANGUAGE PatternSynonyms #-}
66
#endif
7+
#if __GLASGOW_HASKELL__ >= 708
8+
{-# LANGUAGE RoleAnnotations #-}
9+
#endif
710
#if __GLASGOW_HASKELL__ >= 706
811
{-# LANGUAGE PolyKinds #-}
912
#endif
13+
#if __GLASGOW_HASKELL__ >= 810
14+
{-# LANGUAGE StandaloneKindSignatures #-}
15+
#endif
1016
#if __GLASGOW_HASKELL__ >= 702
1117
{-# LANGUAGE Trustworthy #-}
1218
#endif
@@ -31,6 +37,10 @@ import Data.Semigroup (Semigroup (..))
3137
import GHC.Exts (Any)
3238
import Unsafe.Coerce (unsafeCoerce)
3339

40+
#if __GLASGOW_HASKELL__ >= 810
41+
import Data.Kind (Type)
42+
#endif
43+
3444
import Data.GADT.Compare
3545
import Data.GADT.DeepSeq
3646
import Data.GADT.Show
@@ -80,7 +90,14 @@ import Data.GADT.Show
8090
-- >>> read "mkSome TagInt" :: Some Tag
8191
-- Some TagInt
8292
--
93+
#if __GLASGOW_HASKELL__ >= 810
94+
type Some :: (k -> Type) -> Type
95+
#endif
8396
newtype Some tag = UnsafeSome (tag Any)
97+
98+
#if __GLASGOW_HASKELL__ >= 708
99+
type role Some representational
100+
#endif
84101

85102
#if __GLASGOW_HASKELL__ >= 801
86103
{-# COMPLETE Some #-}

0 commit comments

Comments
 (0)