summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2023-03-25 20:28:57 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2023-03-25 20:32:19 -0400
commit56656954bc12efee009c9c0739e9e67153706379 (patch)
treee68756ebf4831c7ad2033e31a347f0b73f36c37c
parent656d4cb3e3a450ececcc72ffd2aca6f8e6489102 (diff)
downloadhaskell-wip/clc-149.tar.gz
Add COMPLETE pragmas to TypeRep, SSymbol, SChar, and SNatwip/clc-149
This implements [CLC proposal #149](https://github.com/haskell/core-libraries-committee/issues/149).
-rw-r--r--libraries/base/Data/Typeable/Internal.hs1
-rw-r--r--libraries/base/GHC/TypeLits.hs2
-rw-r--r--libraries/base/GHC/TypeNats.hs1
-rw-r--r--libraries/base/changelog.md2
-rw-r--r--libraries/base/tests/CLC149.hs23
-rw-r--r--libraries/base/tests/all.T1
6 files changed, 30 insertions, 0 deletions
diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index 2700a2d2fe..3e979dbb8a 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -272,6 +272,7 @@ typeableInstance rep = withTypeable rep TypeableInstance
pattern TypeRep :: forall {k :: Type} (a :: k). () => Typeable @k a => TypeRep @k a
pattern TypeRep <- (typeableInstance -> TypeableInstance)
where TypeRep = typeRep
+{-# COMPLETE TypeRep #-}
{- Note [TypeRep fingerprints]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/libraries/base/GHC/TypeLits.hs b/libraries/base/GHC/TypeLits.hs
index ee88741a12..0bd3632a45 100644
--- a/libraries/base/GHC/TypeLits.hs
+++ b/libraries/base/GHC/TypeLits.hs
@@ -363,6 +363,7 @@ newtype SSymbol (s :: Symbol) = UnsafeSSymbol String
pattern SSymbol :: forall s. () => KnownSymbol s => SSymbol s
pattern SSymbol <- (knownSymbolInstance -> KnownSymbolInstance)
where SSymbol = symbolSing
+{-# COMPLETE SSymbol #-}
-- An internal data type that is only used for defining the SSymbol pattern
-- synonym.
@@ -464,6 +465,7 @@ newtype SChar (s :: Char) = UnsafeSChar Char
pattern SChar :: forall c. () => KnownChar c => SChar c
pattern SChar <- (knownCharInstance -> KnownCharInstance)
where SChar = charSing
+{-# COMPLETE SChar #-}
-- An internal data type that is only used for defining the SChar pattern
-- synonym.
diff --git a/libraries/base/GHC/TypeNats.hs b/libraries/base/GHC/TypeNats.hs
index 668df1e032..970eb917ae 100644
--- a/libraries/base/GHC/TypeNats.hs
+++ b/libraries/base/GHC/TypeNats.hs
@@ -367,6 +367,7 @@ newtype SNat (n :: Nat) = UnsafeSNat Natural
pattern SNat :: forall n. () => KnownNat n => SNat n
pattern SNat <- (knownNatInstance -> KnownNatInstance)
where SNat = natSing
+{-# COMPLETE SNat #-}
-- An internal data type that is only used for defining the SNat pattern
-- synonym.
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 5e0b416cc4..9cdbaaa386 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -16,6 +16,8 @@
([CLC proposal #57](https://github.com/haskell/core-libraries-committee/issues/57))
* Add `Eq` and `Ord` instances for `SSymbol`, `SChar`, and `SNat`.
([CLC proposal #148](https://github.com/haskell/core-libraries-committee/issues/148))
+ * Add `COMPLETE` pragmas to the `TypeRep`, `SSymbol`, `SChar`, and `SNat` pattern synonyms.
+ ([CLC proposal #149](https://github.com/haskell/core-libraries-committee/issues/149))
## 4.18.0.0 *TBA*
* Shipped with GHC 9.6.1
diff --git a/libraries/base/tests/CLC149.hs b/libraries/base/tests/CLC149.hs
new file mode 100644
index 0000000000..dbe316421e
--- /dev/null
+++ b/libraries/base/tests/CLC149.hs
@@ -0,0 +1,23 @@
+-- Test the COMPLETE pragmas for SChar, SNat, SSymbol, and TypeRep.
+{-# OPTIONS_GHC -Wincomplete-patterns #-}
+module CLC149 where
+
+import Data.Kind
+import GHC.TypeLits
+import Type.Reflection
+
+type Dict :: Constraint -> Type
+data Dict c where
+ Dict :: c => Dict c
+
+sc :: SChar c -> Dict (KnownChar c)
+sc SChar = Dict
+
+sn :: SNat n -> Dict (KnownNat n)
+sn SNat = Dict
+
+ss :: SSymbol s -> Dict (KnownSymbol s)
+ss SSymbol = Dict
+
+tr :: TypeRep a -> Dict (Typeable a)
+tr TypeRep = Dict
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index ea9982fac4..fbe628793c 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -296,3 +296,4 @@ test('T22816', normal, compile_and_run, [''])
test('trace', normal, compile_and_run, [''])
test('listThreads', js_broken(22261), compile_and_run, [''])
test('inits1tails1', normal, compile_and_run, [''])
+test('CLC149', normal, compile, [''])