Skip to content

Add a suitable {-# WARNING in "x-partial" ... #-} to Data.List.{init,last} #292

@mpilgrem

Description

@mpilgrem

Following the past decisions in respect of Data.List.head and Data.List.tail in:

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:

  1. that other (total) functions in base are defined in terms of Data.List.init or Data.List.last. For example, Data.List.NonEmpty.init:
    init :: NonEmpty a -> [a]
    init ~(a :| as) = List.init (a : as)
  2. that Cabal's autogenerated Paths_<package_name>.hs module makes use of Data.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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedApproved by CLC voteawaits-mergeApproved, but MR is still unmerged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions