What
CLC has approved the proposal to export foldl'
from class Foldable
from Prelude
.
Before:
module Prelude (
...
Foldable(elem, foldMap, foldr, foldl, foldr1, foldl1, maximum, minimum, product, sum),
...
After:
module Prelude (
...
Foldable(elem, foldMap, foldr, foldl, foldl', foldr1, foldl1, maximum, minimum, product, sum),
...
When
The change might happen in GHC 9.8 / base-4.19
, but more likely to be delayed until GHC 9.10 / base-4.20
.
How
While adding new entities is not a breaking change according to PVP, some packages might be broken, because:
- people can and have defined their own
foldl'
s, causing ambiguity errors, - it can cause new redundant import warnings
However, the breakage is of limited scope, see an impact analysis and linked pull requests covering all Stackage packages.
The migration strategy for this change is backward-compatible: you can migrate already and still retain compatibility with existing GHCs. Because of this, CLC suggests applying patches at your earliest convenience.
-
To avoid ambiguity errors with your own versions of
foldl'
, we recommend qualifying the usages of your version. -
To avoid redundant and dodgy import warnings, please hide
Foldable(..)
fromPrelude
.For example, if your code used to import
foldl'
fromData.Foldable
orData.List
explicitly, please changeimport Data.Foldable (foldl')
to
import Prelude hiding (Foldable(..)) import Data.Foldable (Foldable(..))
-
There are niche cases where adding more CPP might be required to avoid warnings:
foldl'
was not a part ofFoldable
beforebase-4.6
, and alsoPrelude
prior tobase-4.8
exported monomorphic list folds, not generalized toFoldable
. If such extremely wide compatibility range is required, the best option is to list all import fromPrelude
explicitly.For an example of this see Future-proof against potential Prelude.foldl' by Bodigrim · Pull Request #10 · ekmett/hybrid-vectors · GitHub.
PR template
Here is a template, which you can use when raising PRs against affected libraries.
Title: Prepare for foldl’ being exported from Prelude
CLC has approved the proposal to export
foldl'
fromPrelude
(Add foldl' to Prelude · Issue #167 · haskell/core-libraries-committee · GitHub).The implementation of the proposal is delayed at least to GHC 9.8, but one can already future-proof code to be compliant with this change in a backwards-compatible way. No CPP required.
Migration guide and more info: https://github.com/haskell/core-libraries-committee/blob/main/guides/export-foldl-prime-prelude.md