[Git][ghc/ghc][master] 2 commits: Export getSolo from Data.Tuple

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Fri Mar 3 16:41:04 UTC 2023



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


Commits:
45af8482 by David Feuer at 2023-03-03T11:40:47-05:00
Export getSolo from Data.Tuple

Proposed in
[CLC proposal #113](https://github.com/haskell/core-libraries-committee/issues/113)
and
[approved by the CLC](https://github.com/haskell/core-libraries-committee/issues/113#issuecomment-1452452191)

- - - - -
0c694895 by David Feuer at 2023-03-03T11:40:47-05:00
Document getSolo

- - - - -


4 changed files:

- docs/users_guide/9.8.1-notes.rst
- libraries/base/Data/Tuple.hs
- libraries/base/changelog.md
- libraries/ghc-prim/GHC/Tuple/Prim.hs


Changes:

=====================================
docs/users_guide/9.8.1-notes.rst
=====================================
@@ -46,6 +46,7 @@ Runtime system
 ``base`` library
 ~~~~~~~~~~~~~~~~
 
+- ``Data.Tuple`` now exports ``getSolo :: Solo a -> a``.
 
 ``ghc-prim`` library
 ~~~~~~~~~~~~~~~~~~~~


=====================================
libraries/base/Data/Tuple.hs
=====================================
@@ -17,6 +17,7 @@
 
 module Data.Tuple
   ( Solo (..)
+  , getSolo
   , fst
   , snd
   , curry
@@ -25,7 +26,7 @@ module Data.Tuple
   ) where
 
 import GHC.Base ()      -- Note [Depend on GHC.Tuple]
-import GHC.Tuple (Solo (..))
+import GHC.Tuple (Solo (..), getSolo)
 
 default ()              -- Double isn't available yet
 


=====================================
libraries/base/changelog.md
=====================================
@@ -7,6 +7,8 @@
   * Refactor `generalCategory` to stop very large literal string being inlined to call-sites.
       ([CLC proposal #130](https://github.com/haskell/core-libraries-committee/issues/130))
   * Add INLINABLE pragmas to `generic*` functions in Data.OldList ([CLC proposal #129](https://github.com/haskell/core-libraries-committee/issues/130))
+  * Export `getSolo` from `Data.Tuple`.
+      ([CLC proposal #113](https://github.com/haskell/core-libraries-committee/issues/113))
 
 ## 4.18.0.0 *TBA*
 


=====================================
libraries/ghc-prim/GHC/Tuple/Prim.hs
=====================================
@@ -79,6 +79,26 @@ data () = ()
 -- implementations of lazy and strict mapping functions.
 data Solo a = MkSolo a
 
+-- | Extract the value from a 'Solo'. Very often, values should be extracted
+-- directly using pattern matching, to control just what gets evaluated when.
+-- @getSolo@ is for convenience in situations where that is not the case:
+--
+-- When the result is passed to a /strict/ function, it makes no difference
+-- whether the pattern matching is done on the \"outside\" or on the
+-- \"inside\":
+--
+-- @
+-- Data.Set.insert (getSolo sol) set === case sol of Solo v -> Data.Set.insert v set
+-- @
+--
+-- A traversal may be performed in 'Solo' in order to control evaluation
+-- internally, while using @getSolo@ to extract the final result. A strict
+-- mapping function, for example, could be defined
+--
+-- @
+-- map' :: Traversable t => (a -> b) -> t a -> t b
+-- map' f = getSolo . traverse ((Solo $!) . f)
+-- @
 getSolo :: Solo a -> a
 -- getSolo is a standalone function, rather than a record field of Solo,
 -- because Solo is a wired-in TyCon, and a wired-in TyCon that  has



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2f97c86151d7eed115ddcbdee1842684aed63176...0c6948957f62d96a8234683fdf67b34369aad240

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2f97c86151d7eed115ddcbdee1842684aed63176...0c6948957f62d96a8234683fdf67b34369aad240
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/20230303/0b2bf984/attachment-0001.html>


More information about the ghc-commits mailing list