diff options
author | Oleg Grenrus <oleg.grenrus@iki.fi> | 2022-11-29 19:34:11 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-11 12:26:17 -0500 |
commit | b3e98a926ac05b8e59e3b31b74b019d4ecb462f6 (patch) | |
tree | 31dca72717b5668255cc546beead951a83b03c2b /libraries | |
parent | c658c580863fc23c29f183db3f52a2004756d84c (diff) | |
download | haskell-b3e98a926ac05b8e59e3b31b74b019d4ecb462f6.tar.gz |
Add heqT, a kind-heterogeneous variant of heq
CLC proposal https://github.com/haskell/core-libraries-committee/issues/99
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Typeable.hs | 12 | ||||
-rw-r--r-- | libraries/base/changelog.md | 1 |
2 files changed, 11 insertions, 2 deletions
diff --git a/libraries/base/Data/Typeable.hs b/libraries/base/Data/Typeable.hs index 2ac9f9ade0..6885152308 100644 --- a/libraries/base/Data/Typeable.hs +++ b/libraries/base/Data/Typeable.hs @@ -4,6 +4,7 @@ {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} ----------------------------------------------------------------------------- @@ -56,6 +57,7 @@ module Data.Typeable -- * Type-safe cast , cast , eqT + , heqT , gcast -- a generalisation of cast -- * Generalized casts for higher-order kinds @@ -135,8 +137,14 @@ cast x -- @since 4.7.0.0 eqT :: forall a b. (Typeable a, Typeable b) => Maybe (a :~: b) eqT - | Just HRefl <- ta `I.eqTypeRep` tb = Just Refl - | otherwise = Nothing + | Just HRefl <- heqT @a @b = Just Refl + | otherwise = Nothing + +-- | Extract a witness of heterogeneous equality of two types +-- +-- @since 4.18.0.0 +heqT :: forall a b. (Typeable a, Typeable b) => Maybe (a :~~: b) +heqT = ta `I.eqTypeRep` tb where ta = I.typeRep :: I.TypeRep a tb = I.typeRep :: I.TypeRep b diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index ee712fe27c..01dd9fe894 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -57,6 +57,7 @@ of individually allocated pointers as well as freeing each one of them when freeing a `Pool`. (#14762) (#18338) * `Type.Reflection.Unsafe` is now marked as unsafe. + * Add `Data.Typeable.heqT`, a kind-heterogeneous version of `Data.Typeable.eqT`. ## 4.17.0.0 *August 2022* |