purescript/purescript-foldable-traversable

foldr1 and foldl1 are too restrictive

Opened this issue · 1 comments

Should the signature of foldr1 (and similarly foldl1) be:

foldr1 :: forall f a b. Foldable1 f => (a -> b -> b) -> (a -> b) -> f a -> b

I understand the logic behind the current signature:

foldr1 :: forall f a b. Foldable1 f => (b -> b -> b) -> f b -> b

In that, if I have a mapping from a -> b, then I can pre-map unconditionally, and derive the latter signature. Unfortunately that's not actually what I want to do:

  • I only want the mapping to apply to the terminal value.
  • I want to otherwise combine with the combining function.
  • I don't want to waste an entire traversal to make the signature work.

I feel like there's a missed opportunity with the current signature. To be honest, I almost never want the current signature.

I'd be ok with making a breaking change release outside of the compiler changes. However, how would that be handled?