1
1
{-# LANGUAGE CPP #-}
2
2
{-# LANGUAGE DeriveDataTypeable #-}
3
3
{-# LANGUAGE GADTs #-}
4
+ {-# LANGUAGE QuantifiedConstraints #-}
4
5
{-# LANGUAGE RankNTypes #-}
5
6
{-# LANGUAGE ScopedTypeVariables #-}
6
7
{-# LANGUAGE TypeOperators #-}
7
- #if __GLASGOW_HASKELL__ >= 706
8
8
{-# LANGUAGE PolyKinds #-}
9
- #endif
10
- #if __GLASGOW_HASKELL__ >= 708
11
9
{-# LANGUAGE RoleAnnotations #-}
12
- #endif
13
10
#if __GLASGOW_HASKELL__ >= 810
14
11
{-# LANGUAGE StandaloneKindSignatures #-}
15
12
#endif
16
13
#if __GLASGOW_HASKELL__ >= 800 && __GLASGOW_HASKELL__ < 805
17
14
{-# LANGUAGE TypeInType #-}
18
15
#endif
19
- #if (__GLASGOW_HASKELL__ >= 704 && __GLASGOW_HASKELL__ < 707) || __GLASGOW_HASKELL__ >= 801
20
- {-# LANGUAGE Safe #-}
21
- #elif __GLASGOW_HASKELL__ >= 702
22
- {-# LANGUAGE Trustworthy #-}
23
- #endif
16
+ {-# LANGUAGE StandaloneDeriving #-}
17
+ {-# LANGUAGE Safe #-}
18
+
19
+ -- For GShow
20
+ {-# LANGUAGE FlexibleInstances #-}
21
+ {-# LANGUAGE UndecidableInstances #-}
22
+
24
23
module Data.GADT.Internal where
25
24
26
25
import Control.Applicative (Applicative (.. ))
@@ -34,9 +33,7 @@ import Data.Type.Equality ((:~:) (..))
34
33
import GHC.Generics ((:+:) (.. ), (:*:) (.. ))
35
34
#endif
36
35
37
- #if __GLASGOW_HASKELL__ >=708
38
36
import Data.Typeable (Typeable )
39
- #endif
40
37
41
38
#if MIN_VERSION_base(4,9,0)
42
39
#if MIN_VERSION_base(4,10,0)
@@ -59,6 +56,7 @@ import Data.Kind (Type)
59
56
import Data.Kind (Constraint )
60
57
#endif
61
58
59
+ {-# DEPRECATED GShow "Just use the underlying quantified constraint" #-}
62
60
-- $setup
63
61
-- >>> :set -XKindSignatures -XGADTs -XTypeOperators
64
62
-- >>> import Data.Type.Equality
@@ -69,12 +67,12 @@ import Data.Kind (Constraint)
69
67
-- like @(forall a. Show (t a)) => ...@. The easiest way to create instances would probably be
70
68
-- to write (or derive) an @instance Show (T a)@, and then simply say:
71
69
--
72
- -- > instance GShow t where gshowsPrec = defaultGshowsPrec
73
- #if __GLASGOW_HASKELL__ >= 810
74
- type GShow :: ( k -> Type ) -> Constraint
75
- #endif
76
- class GShow t where
77
- gshowsPrec :: Int -> t a -> ShowS
70
+ -- > instance GShow t
71
+ class ( forall a . Show ( t a )) => GShow t
72
+ instance ( forall a . Show ( t a )) => GShow t
73
+
74
+ gshowsPrec :: GShow t => Int -> t a -> ShowS
75
+ gshowsPrec = showsPrec
78
76
79
77
-- | If 'f' has a 'Show (f a)' instance, this function makes a suitable default
80
78
-- implementation of 'gshowsPrec'.
@@ -89,59 +87,6 @@ gshows = gshowsPrec (-1)
89
87
gshow :: (GShow t ) => t a -> String
90
88
gshow x = gshows x " "
91
89
92
- instance GShow ((:~: ) a ) where
93
- gshowsPrec _ Refl = showString " Refl"
94
-
95
- #if MIN_VERSION_base(4,9,0)
96
- -- | @since 1.0.4
97
- instance GShow ((:~~: ) a ) where
98
- gshowsPrec _ HRefl = showString " HRefl"
99
- #endif
100
-
101
- #if MIN_VERSION_base(4,10,0)
102
- instance GShow TR. TypeRep where
103
- gshowsPrec = showsPrec
104
- #endif
105
-
106
- --
107
- -- | >>> gshow (InL Refl :: Sum ((:~:) Int) ((:~:) Bool) Int)
108
- -- "InL Refl"
109
- instance (GShow a , GShow b ) => GShow (Sum a b ) where
110
- gshowsPrec d = \ s -> case s of
111
- InL x -> showParen (d > 10 ) (showString " InL " . gshowsPrec 11 x)
112
- InR x -> showParen (d > 10 ) (showString " InR " . gshowsPrec 11 x)
113
-
114
- -- | >>> gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)
115
- -- "Pair Refl Refl"
116
- instance (GShow a , GShow b ) => GShow (Product a b ) where
117
- gshowsPrec d (Pair x y) = showParen (d > 10 )
118
- $ showString " Pair "
119
- . gshowsPrec 11 x
120
- . showChar ' '
121
- . gshowsPrec 11 y
122
-
123
- #if MIN_VERSION_base(4,6,0)
124
- --
125
- -- | >>> gshow (L1 Refl :: ((:~:) Int :+: (:~:) Bool) Int)
126
- -- "L1 Refl"
127
- --
128
- -- @since 1.0.4
129
- instance (GShow a , GShow b ) => GShow (a :+: b ) where
130
- gshowsPrec d = \ s -> case s of
131
- L1 x -> showParen (d > 10 ) (showString " L1 " . gshowsPrec 11 x)
132
- R1 x -> showParen (d > 10 ) (showString " R1 " . gshowsPrec 11 x)
133
-
134
- -- | >>> gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)
135
- -- "Refl :*: Refl"
136
- --
137
- -- @since 1.0.4
138
- instance (GShow a , GShow b ) => GShow (a :*: b ) where
139
- gshowsPrec d (x :*: y) = showParen (d > 6 )
140
- $ gshowsPrec 6 x
141
- . showString " :*: "
142
- . gshowsPrec 6 y
143
- #endif
144
-
145
90
-- | @GReadS t@ is equivalent to @ReadS (forall b. (forall a. t a -> b) -> b)@, which is
146
91
-- in turn equivalent to @ReadS (Exists t)@ (with @data Exists t where Exists :: t a -> Exists t@)
147
92
#if __GLASGOW_HASKELL__ >= 810
@@ -164,6 +109,9 @@ type GRead :: (k -> Type) -> Constraint
164
109
class GRead t where
165
110
greadsPrec :: Int -> GReadS t
166
111
112
+ -- (forall a. Read (t a)) =>
113
+ -- Skipping because it is rather misleading to use.
114
+
167
115
greads :: GRead t => GReadS t
168
116
greads = greadsPrec (- 1 )
169
117
@@ -240,7 +188,7 @@ instance (GRead a, GRead b) => GRead (a :+: b) where
240
188
#if __GLASGOW_HASKELL__ >= 810
241
189
type GEq :: (k -> Type ) -> Constraint
242
190
#endif
243
- class GEq f where
191
+ class ( forall a . Eq ( f a )) => GEq f where
244
192
-- | Produce a witness of type-equality, if one exists.
245
193
--
246
194
-- A handy idiom for using this would be to pattern-bind in the Maybe monad, eg.:
@@ -357,9 +305,21 @@ data GOrdering a b where
357
305
GLT :: GOrdering a b
358
306
GEQ :: GOrdering t t
359
307
GGT :: GOrdering a b
360
- #if __GLASGOW_HASKELL__ >=708
361
308
deriving Typeable
362
- #endif
309
+
310
+ deriving instance Eq (GOrdering a b )
311
+ deriving instance Ord (GOrdering a b )
312
+ deriving instance Show (GOrdering a b )
313
+
314
+ {-
315
+ instance Read (GOrdering a b) where
316
+ readsPrec _ s = case con of
317
+ "GGT" -> [(GGT, rest)]
318
+ "GEQ" -> [] -- cannot read without evidence of equality
319
+ "GLT" -> [(GLT, rest)]
320
+ _ -> []
321
+ where (con, rest) = splitAt 3 s
322
+ -}
363
323
364
324
-- | TODO: Think of a better name
365
325
--
@@ -369,20 +329,6 @@ weakenOrdering GLT = LT
369
329
weakenOrdering GEQ = EQ
370
330
weakenOrdering GGT = GT
371
331
372
- instance Eq (GOrdering a b ) where
373
- x == y = weakenOrdering x == weakenOrdering y
374
-
375
- instance Ord (GOrdering a b ) where
376
- compare x y = compare (weakenOrdering x) (weakenOrdering y)
377
-
378
- instance Show (GOrdering a b ) where
379
- showsPrec _ GGT = showString " GGT"
380
- showsPrec _ GEQ = showString " GEQ"
381
- showsPrec _ GLT = showString " GLT"
382
-
383
- instance GShow (GOrdering a ) where
384
- gshowsPrec = showsPrec
385
-
386
332
instance GRead (GOrdering a ) where
387
333
greadsPrec _ s = case con of
388
334
" GGT" -> [(mkSome GGT , rest)]
@@ -396,7 +342,7 @@ instance GRead (GOrdering a) where
396
342
#if __GLASGOW_HASKELL__ >= 810
397
343
type GCompare :: (k -> Type ) -> Constraint
398
344
#endif
399
- class GEq f => GCompare f where
345
+ class ( GEq f , forall a . Ord ( f a )) => GCompare f where
400
346
gcompare :: f a -> f b -> GOrdering a b
401
347
402
348
instance GCompare ((:~: ) a ) where
@@ -513,9 +459,7 @@ newtype Some tag = S
513
459
withSome :: forall r . (forall a . tag a -> r ) -> r
514
460
}
515
461
516
- #if __GLASGOW_HASKELL__ >= 708
517
462
type role Some representational
518
- #endif
519
463
520
464
-- | Constructor.
521
465
mkSome :: tag a -> Some tag
0 commit comments