[Git][ghc/ghc][master] Re CLC #293 - Don't specify Data.List.NonEmpty in terms of partial

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu Nov 7 09:34:46 UTC 2024



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


Commits:
8e217256 by Mike Pilgrem at 2024-11-07T04:34:20-05:00
Re CLC #293 - Don't specify Data.List.NonEmpty in terms of partial

See https://github.com/haskell/core-libraries-committee/issues/293

`List.init` had already been driven out of `tails1` by 21fc180bec93d964a7f4ffdf2429ef6f74b49ab6 but this specification also avoided partial `fromList`, so I preferred it.

The `changelog.md` for `base` is updated, with an entry added under `base-4.22.0.0`.

- - - - -


2 changed files:

- libraries/base/changelog.md
- libraries/base/src/Data/List/NonEmpty.hs


Changes:

=====================================
libraries/base/changelog.md
=====================================
@@ -4,6 +4,7 @@
   * Restrict `Data.List.NonEmpty.unzip` to `NonEmpty (a, b) -> (NonEmpty a, NonEmpty b)`. ([CLC proposal #86](https://github.com/haskell/core-libraries-committee/issues/86))
   * Modify the implementation of `Control.Exception.throw` to avoid call-sites being inferred as diverging via precise exception.
     ([GHC #25066](https://gitlab.haskell.org/ghc/ghc/-/issues/25066), [CLC proposal #290](https://github.com/haskell/core-libraries-committee/issues/290))
+  * `Data.List.NonEmpty.{init,last,tails1}` are now defined using only total functions (rather than partial ones). ([CLC proposal #293](https://github.com/haskell/core-libraries-committee/issues/293))
 
 ## 4.21.0.0 *TBA*
   * `GHC.Desugar` has been deprecated and should be removed in GHC 9.14. ([CLC proposal #216](https://github.com/haskell/core-libraries-committee/issues/216))


=====================================
libraries/base/src/Data/List/NonEmpty.hs
=====================================
@@ -206,11 +206,13 @@ tail (_ :| as) = as
 
 -- | Extract the last element of the stream.
 last :: NonEmpty a -> a
-last ~(a :| as) = List.last (a : as)
+last (a :| []) = a
+last (_ :| (a : as)) = last (a :| as)
 
 -- | Extract everything except the last element of the stream.
 init :: NonEmpty a -> [a]
-init ~(a :| as) = List.init (a : as)
+init (_ :| []) = []
+init (a1 :| (a2 : as)) = a1 : init (a2 :| as)
 
 -- | Construct a 'NonEmpty' list from a single element.
 --
@@ -324,7 +326,7 @@ tails = fromList . List.tails . Foldable.toList
 --
 -- @since 4.18
 tails1 :: NonEmpty a -> NonEmpty (NonEmpty a)
-tails1 = fromList . List.tails1 . Foldable.toList
+tails1 xs = xs :| List.tails1 (tail xs)
 
 -- | @'insert' x xs@ inserts @x@ into the last position in @xs@ where it
 -- is still less than or equal to the next element. In particular, if the



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8e217256520adc148ccb78e9c518c80cff92525f
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/20241107/0734593c/attachment-0001.html>


More information about the ghc-commits mailing list