summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorVladislav Zavialov <vlad.z.4096@gmail.com>2021-03-14 19:45:51 +0300
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-17 19:09:40 -0400
commit302854154626ef10363afdda3ff1db7160e0827f (patch)
tree2d438461f8a7452797dc626eb0ba6cdb8b194b61 /libraries
parent26d26974f5d16a3b2c6ec84a739caab10c7d2b07 (diff)
downloadhaskell-302854154626ef10363afdda3ff1db7160e0827f.tar.gz
Built-in type families: CharToNat, NatToChar (#19535)
Co-authored-by: Daniel Rogozin <daniel.rogozin@serokell.io> Co-authored-by: Rinat Stryungis <rinat.stryungis@serokell.io>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/GHC/TypeLits.hs11
-rw-r--r--libraries/base/changelog.md5
2 files changed, 16 insertions, 0 deletions
diff --git a/libraries/base/GHC/TypeLits.hs b/libraries/base/GHC/TypeLits.hs
index b0daf341c8..2dcc28b223 100644
--- a/libraries/base/GHC/TypeLits.hs
+++ b/libraries/base/GHC/TypeLits.hs
@@ -50,6 +50,7 @@ module GHC.TypeLits
, AppendSymbol
, N.CmpNat, CmpSymbol, CmpChar
, ConsSymbol, UnconsSymbol
+ , CharToNat, NatToChar
-- * User-defined type errors
, TypeError
@@ -240,6 +241,16 @@ type family ConsSymbol (a :: Char) (b :: Symbol) :: Symbol
-- @since 4.16.0.0
type family UnconsSymbol (a :: Symbol) :: Maybe (Char, Symbol)
+-- | Convert a character to its Unicode code point (cf. `Data.Char.ord`)
+--
+-- @since 4.16.0.0
+type family CharToNat (c :: Char) :: N.Nat
+
+-- | Convert a Unicode code point to a character (cf. `Data.Char.chr`)
+--
+-- @since 4.16.0.0
+type family NatToChar (n :: N.Nat) :: Char
+
--------------------------------------------------------------------------------
-- | We either get evidence that this function was instantiated with the
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index fcf9c0dde6..6cf4561225 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -16,6 +16,11 @@
* Add `cmpNat`, `cmpSymbol`, and `cmpChar` to `GHC.TypeNats` and `GHC.TypeLits`.
+ * Add `CmpChar`, `ConsSymbol`, `UnconsSymbol`, `CharToNat`, and `NatToChar`
+ type families to `GHC.TypeLits`.
+
+ * Add the `KnownChar` class, `charVal` and `charVal'` to `GHC.TypeLits`.
+
* Add `Semigroup` and `Monoid` instances for `Data.Functor.Product` and
`Data.Functor.Compose`.