summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/GHC/TypeLits.hs26
-rw-r--r--libraries/base/changelog.md3
2 files changed, 29 insertions, 0 deletions
diff --git a/libraries/base/GHC/TypeLits.hs b/libraries/base/GHC/TypeLits.hs
index f124017be2..0d9f4fe61f 100644
--- a/libraries/base/GHC/TypeLits.hs
+++ b/libraries/base/GHC/TypeLits.hs
@@ -215,6 +215,32 @@ data {-kind-} ErrorMessage = Text Symbol
infixl 5 :$$:
infixl 6 :<>:
+-- | The type-level equivalent of 'error'.
+--
+-- The polymorphic kind of this type allows it to be used in several settings.
+-- For instance, it can be used as a constraint, e.g. to provide a better error
+-- message for a non-existant instance,
+--
+-- @@
+-- -- in a context
+-- instance TypeError (Text "Cannot 'Show' functions." :$$:
+-- Text "Perhaps there is a missing argument?")
+-- => Show (a -> b) where
+-- showsPrec = error "unreachable"
+-- @@
+--
+-- It can also be placed on the right-hand side of a type-level function
+-- to provide an error for an invalid case,
+--
+-- @@
+-- type family ByteSize x where
+-- ByteSize Word16 = 2
+-- ByteSize Word8 = 1
+-- ByteSize a = TypeError (Text "The type " :<>: ShowType a :<>:
+-- Text " is not exportable.")
+-- @@
+--
+-- @since 4.9.0.0
type family TypeError (a :: ErrorMessage) :: b where
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 74692a703c..f7718facf0 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -91,6 +91,9 @@
* Add `MonadPlus IO` and `Alternative IO` instances
(previously orphans in `transformers`) (#10755)
+ * Add `GHC.TypeLits.TypeError` and `ErrorMessage` to allow users
+ to define custom compile-time error messages.
+
## 4.8.2.0 *Oct 2015*
* Bundled with GHC 7.10.3