diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2015-11-18 12:22:58 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-11-18 12:53:50 +0100 |
commit | c945c90bd910b7e38abd2f98af7783eea281d8f8 (patch) | |
tree | b8f56c8d56853134ffb85be4ea1da305e44368be /libraries | |
parent | 6b3d5b5990b9b306e13575e60d7e1c8ce264b0ef (diff) | |
download | haskell-c945c90bd910b7e38abd2f98af7783eea281d8f8.tar.gz |
base: Documentation for TypeError
Test Plan: Read
Reviewers: yav, hvr, austin
Reviewed By: austin
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1490
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/TypeLits.hs | 26 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
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 |