summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2016-08-18 09:11:03 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2016-08-18 09:11:03 -0400
commit113d50b791c469394d38fab6ce5b760e5e8c35e2 (patch)
tree74ce30e83d9bcfc54de7875f9fc7c5223f4aa779
parentd61027438102e212c47721306d4f294278e95b57 (diff)
downloadhaskell-113d50b791c469394d38fab6ce5b760e5e8c35e2.tar.gz
Add gcoerceWith to Data.Type.Coercion
Summary: For symmetry with `gcastWith` in `Data.Type.Equality`. Fixes #12493. Test Plan: It compiles Reviewers: bgamari, goldfire, hvr, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2456 GHC Trac Issues: #12493
-rw-r--r--docs/users_guide/8.2.1-notes.rst3
-rw-r--r--libraries/base/Data/Type/Coercion.hs8
-rw-r--r--libraries/base/changelog.md2
3 files changed, 13 insertions, 0 deletions
diff --git a/docs/users_guide/8.2.1-notes.rst b/docs/users_guide/8.2.1-notes.rst
index 27b49efa7e..0126427ea0 100644
--- a/docs/users_guide/8.2.1-notes.rst
+++ b/docs/users_guide/8.2.1-notes.rst
@@ -100,6 +100,9 @@ See ``changelog.md`` in the ``base`` package for full release notes.
- ``Data.Either`` now provides ``fromLeft`` and ``fromRight``
+- ``Data.Type.Coercion`` now provides ``gcoerceWith``, which is analogous to
+ ``gcastWith`` from ``Data.Type.Equality``.
+
binary
~~~~~~
diff --git a/libraries/base/Data/Type/Coercion.hs b/libraries/base/Data/Type/Coercion.hs
index 254bb9aecf..318d0983f2 100644
--- a/libraries/base/Data/Type/Coercion.hs
+++ b/libraries/base/Data/Type/Coercion.hs
@@ -7,6 +7,7 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE RankNTypes #-}
-----------------------------------------------------------------------------
-- |
@@ -25,6 +26,7 @@
module Data.Type.Coercion
( Coercion(..)
, coerceWith
+ , gcoerceWith
, sym
, trans
, repr
@@ -56,6 +58,12 @@ data Coercion a b where
coerceWith :: Coercion a b -> a -> b
coerceWith Coercion x = coerce x
+-- | Generalized form of type-safe cast using representational equality
+--
+-- @since 4.10.0.0
+gcoerceWith :: Coercion a b -> (Coercible a b => r) -> r
+gcoerceWith Coercion x = x
+
-- | Symmetry of representational equality
sym :: Coercion a b -> Coercion b a
sym Coercion = Coercion
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 996456f0e6..f8f6b10f30 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -16,6 +16,8 @@
* `Data.Either` now provides `fromLeft` and `fromRight` (#12402)
+ * `Data.Type.Coercion` now provides `gcoerceWith` (#12493)
+
## 4.9.0.0 *May 2016*
* Bundled with GHC 8.0