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
1921module Data.GADT.Internal where
2022
2123import Control.Applicative (Applicative (.. ))
@@ -35,6 +37,10 @@ import Data.Type.Equality (testEquality)
3537import 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
4655class 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
8294type GReadS t = String -> [(Some t , String )]
8395
8496getGReadResult :: 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
93108class 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
142160class 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
222243data 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
262286class 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
346373newtype 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.
352383mkSome :: tag a -> Some tag
353384mkSome t = S (\ f -> f t)
0 commit comments