diff options
author | David Feuer <David.Feuer@gmail.com> | 2023-03-02 11:49:34 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-03-03 11:40:47 -0500 |
commit | 0c6948957f62d96a8234683fdf67b34369aad240 (patch) | |
tree | 7f30ca36f54bc3238539972b35e7b7d2b076897a /libraries | |
parent | 45af8482e3f7d2d8234265982e14ff9b0d4dfa65 (diff) | |
download | haskell-0c6948957f62d96a8234683fdf67b34369aad240.tar.gz |
Document getSolo
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/ghc-prim/GHC/Tuple/Prim.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libraries/ghc-prim/GHC/Tuple/Prim.hs b/libraries/ghc-prim/GHC/Tuple/Prim.hs index 96b1c0c9a6..36c88e4bcb 100644 --- a/libraries/ghc-prim/GHC/Tuple/Prim.hs +++ b/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 |