
Base has: * foldMap :: (Foldable t, Monoid a) => (x -> a) -> t x -> a * foldr1 :: (Foldable t) => (a -> a -> a) -> t x -> a Is there a good reason why it does not have: ``` foldMap1 :: (Foldable t, Semigroup a, Functor f) => (a -> a) -> t x -> a foldMap1 = fodlr1 (<>) . fmap f ``` Like `foldr1` it is partial for any foldable that can be empty. Best regards, Marcin Szamotulski Sent with ProtonMail Secure Email.

Is there a good reason why it does not have: A good question. See - (2017) https://gitlab.haskell.org/ghc/ghc/-/issues/13573 - (2017) https://www.reddit.com/r/haskell/comments/6d0vgt/could_we_have_foldable1_and... - (2019) https://mail.haskell.org/pipermail/libraries/2019-November/030059.html - (2020) https://mail.haskell.org/pipermail/libraries/2020-December/031003.html - (2021) https://twitter.com/kmett/status/1363774888603914242 For recent bits and bobs of the possible answers. - Oleg On 14.5.2021 22.54, coot@coot.me wrote:
Base has: * foldMap :: (Foldable t, Monoid a) => (x -> a) -> t x -> a * foldr1 :: (Foldable t) => (a -> a -> a) -> t x -> a Is there a good reason why it does not have: ``` foldMap1 :: (Foldable t, Semigroup a, Functor f) => (a -> a) -> t x -> a foldMap1 = fodlr1 (<>) . fmap f ``` Like `foldr1` it is partial for any foldable that can be empty.
Best regards, Marcin Szamotulski
Sent with ProtonMail Secure Email.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Fri, 14 May 2021, coot@coot.me wrote:
Base has: * foldMap :: (Foldable t, Monoid a) => (x -> a) -> t x -> a * foldr1 :: (Foldable t) => (a -> a -> a) -> t x -> a Is there a good reason why it does not have: ``` foldMap1 :: (Foldable t, Semigroup a, Functor f) => (a -> a) -> t x -> a foldMap1 = fodlr1 (<>) . fmap f ``` Like `foldr1` it is partial for any foldable that can be empty.
I do not think we should extend support for partial functions. foldMap1 should be restricted to non-empty Foldable (i.e. Foldable1).

Thanks Oleg, I would love to see `Foldable1` to be in base.
This seems to be a topic that comes back again and again, so I am not sure why there's a lack of decision so far.
There is a whole ecosystem of non empty data types: `nonempty-containers`, `nonempty-vector`, `nonempty-dlist`, `nonempty-lift` and the most funny one `Identity` from `base` - the nonempty `Maybe` ;). For all of them `Foldable1` instance are non partial. Isn't this a good enough argument to move `Foldable1` to base?
Maybe this could go through HF to help facilitate the decision?
My recent discovery why I'd like to have it is a last-to-finish synchronisation which is a semigroup:
https://github.com/input-output-hk/ouroboros-network/blob/coot/last-to-finis...
There's also last-to-finish based on `Ap`. The `LastToFinish m a` does not require Monoid instance on `a`, unlike `Ap a`, so it is easier to use, but it requires `foldMap1` which is not in `base`.
Cheers,
Marcin
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, May 14th, 2021 at 23:11, Henning Thielemann
On Fri, 14 May 2021, coot@coot.me wrote:
Base has:
- foldMap :: (Foldable t, Monoid a) => (x -> a) -> t x -> a - foldr1 :: (Foldable t) => (a -> a -> a) -> t x -> a
Is there a good reason why it does not have:
foldMap1 :: (Foldable t, Semigroup a, Functor f) => (a -> a) -> t x -> a foldMap1 = fodlr1 (<>) . fmap f
Like `foldr1` it is partial for any foldable that can be empty.
I do not think we should extend support for partial functions.
foldMap1 should be restricted to non-empty Foldable (i.e. Foldable1).
participants (3)
-
coot@coot.me
-
Henning Thielemann
-
Oleg Grenrus