diff options
author | Bodigrim <andrew.lelechenko@gmail.com> | 2022-11-05 12:56:18 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-03-30 14:35:57 -0400 |
commit | 61a2dfaa1ab4e1502c0ab00818150de0a033412a (patch) | |
tree | 4268ca29001f8300cc9649af1a1ca2862775cfa1 /libraries | |
parent | 98b5cf67f8428b0daefcbf5df121df0b8a126654 (diff) | |
download | haskell-61a2dfaa1ab4e1502c0ab00818150de0a033412a.tar.gz |
Add {-# WARNING #-} to Data.List.{head,tail}
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/List.hs | 4 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/libraries/base/GHC/List.hs b/libraries/base/GHC/List.hs index b8a34e20e1..c5109fcf38 100644 --- a/libraries/base/GHC/List.hs +++ b/libraries/base/GHC/List.hs @@ -83,6 +83,8 @@ head (x:_) = x head [] = badHead {-# NOINLINE [1] head #-} +{-# WARNING in "x-partial" head "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." #-} + badHead :: HasCallStack => a badHead = errorEmptyList "head" @@ -129,6 +131,8 @@ tail :: HasCallStack => [a] -> [a] tail (_:xs) = xs tail [] = errorEmptyList "tail" +{-# WARNING in "x-partial" tail "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." #-} + -- | \(\mathcal{O}(n)\). Extract the last element of a list, which must be -- finite and non-empty. -- diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index 9cdbaaa386..76a79abb3f 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -1,6 +1,9 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) ## 4.19.0.0 *TBA* + * Add `{-# WARNING in "x-partial" #-}` to `Data.List.{head,tail}`. + Use `{-# OPTIONS_GHC -Wno-x-partial #-}` to disable it. + ([CLC proposal #87](https://github.com/haskell/core-libraries-committee/issues/87) and [#114](https://github.com/haskell/core-libraries-committee/issues/114)) * Add `Data.List.!?` ([CLC proposal #110](https://github.com/haskell/core-libraries-committee/issues/110)) * `maximumBy`/`minimumBy` are now marked as `INLINE` improving performance for unpackable types significantly. |