[Git][ghc/ghc][master] docs: document permissibility of -XOverloadedLabels (#24249)

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Mon Dec 25 21:01:47 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
c247b6be by Zubin Duggal at 2023-12-25T16:01:23-05:00
docs: document permissibility of -XOverloadedLabels (#24249)

Document the permissibility introduced by
https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0170-unrestricted-overloadedlabels.rst

- - - - -


1 changed file:

- docs/users_guide/exts/overloaded_labels.rst


Changes:

=====================================
docs/users_guide/exts/overloaded_labels.rst
=====================================
@@ -91,4 +91,69 @@ showing how an overloaded label can be used as a record selector:
     example = #x (Point 1 2)
 
 
+Since GHC 9.6, any non-empty double quoted string can be used as a label. The
+restriction that the label must be a valid identifier has also been lifted.
 
+Examples of newly allowed syntax:
+
+- Leading capital letters: `#Foo` equivalant to `getLabel @"Foo"`
+
+- Numeric characters: `#3.14` equivalent to `getLabel @"3.14"`
+
+- Arbitrary strings: `#"Hello, World!"` equivalent to `getLabel @"Hello, World!"`
+
+Here is an example of the more permissive use of this extension, available since
+GHC 9.6:
+
+::
+
+    {-# LANGUAGE DataKinds             #-}
+    {-# LANGUAGE MultiParamTypeClasses #-}
+    {-# LANGUAGE OverloadedLabels      #-}
+    {-# LANGUAGE MagicHash             #-}
+
+    import Data.Foldable (traverse_)
+    import Data.Proxy (Proxy(..))
+    import GHC.OverloadedLabels (IsLabel(..))
+    import GHC.TypeLits (KnownSymbol, symbolVal)
+    import GHC.Prim (Addr#)
+
+    instance KnownSymbol symbol => IsLabel symbol String where
+      fromLabel = symbolVal (Proxy :: Proxy symbol)
+
+    (#) :: String -> Int -> String
+    (#) _ i = show i
+
+    f :: Addr# -> Int -> String
+    f _ i = show i
+
+    main :: IO ()
+    main = traverse_ putStrLn
+      [ #a
+      , #number17
+      , #do
+      , #type
+      , #Foo
+      , #3
+      , #199.4
+      , #17a23b
+      , #f'a'
+      , #'a'
+      , #'
+      , #''notTHSplice
+      , #...
+      , #привет
+      , #こんにちは
+      , #"3"
+      , #":"
+      , #"Foo"
+      , #"The quick brown fox"
+      , #"\""
+      , (++) #hello#world
+      , (++) #"hello"#"world"
+      , #"hello"# 1 -- equivalent to `(fromLabel @"hello") # 1`
+      , f "hello"#2 -- equivalent to `f ("hello"# :: Addr#) 2`
+      ]
+
+See `GHC Proposal #170 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0170-unrestricted-overloadedlabels.rst>`__
+for more details.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c247b6befe6a599688bad0a3383424f7ea12d5f2

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c247b6befe6a599688bad0a3383424f7ea12d5f2
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20231225/20de5d2d/attachment-0001.html>


More information about the ghc-commits mailing list