Skip to content

foldr1 and foldl1 are too restrictive #151

Description

@natefaubion

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: breaking changeA change that requires a major version bump.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions