-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Following the past decisions in respect of Data.List.head
and Data.List.tail
in:
- Add {-# WARNING #-} to Data.List.{head,tail} #87
- Add warning category to WARNINGs on Data.List.{head,tail} #114
implemented in base-4.19.0.0
(GHC 9.8.1), which also added Data.List.unsnoc
, I propose, for consistency, that the same idea is extended to Data.List.init
and Data.List.last
. Their Haddock documentation has warned that they are partial and suggested alternatives since base-4.17.0.0
(GHC 9.4.1).
The basis for the proposal is purely consistency of treatment of Data.List.{head,tail,init,last}
. It seems to me that the principal merits and drawbacks applicable to head
and tail
, discussed at some length in the past approved proposals, are equally applicable to init
and last
.
@Bodigrim, on introducing #87 (at #87 (comment)), gave as a reason that it was not extended then to init
or last
that doing so would require Data.List.unsnoc
first. That barrier no longer applies.
In case it is relevant, I note:
- that other (total) functions in
base
are defined in terms ofData.List.init
orData.List.last
. For example,Data.List.NonEmpty.init
:init :: NonEmpty a -> [a] init ~(a :| as) = List.init (a : as)
- that Cabal's autogenerated
Paths_<package_name>.hs
module makes use ofData.List.last
- see https://hackage.haskell.org/package/Cabal-3.14.0.0/src/src/Distribution/Simple/Build/PathsModule/Z.hs.
EDIT: The resolution of this issue may depend on the resolution of the following issue, given that this issue provides advice (as does the existing Haddock documentation) about the use of unsnoc
:
CLC update:
- GHC MR: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13564
- GHC issue: https://gitlab.haskell.org/ghc/ghc/-/issues/25852
- Approval: 8 out of 10