Skip to content

Deprecate unlawful Alternative instances for ZipLazyList and ZipStream#4843

Closed
LSUDOKO wants to merge 3 commits intotypelevel:mainfrom
LSUDOKO:fix/ziplist-unlawful-alternative-4840
Closed

Deprecate unlawful Alternative instances for ZipLazyList and ZipStream#4843
LSUDOKO wants to merge 3 commits intotypelevel:mainfrom
LSUDOKO:fix/ziplist-unlawful-alternative-4840

Conversation

@LSUDOKO
Copy link

@LSUDOKO LSUDOKO commented Mar 11, 2026

Fixes #4840

Changes

  1. Deprecated Alternative[ZipLazyList] and Alternative[ZipStream]

    • These instances violate the right distributivity law of Alternative
    • Kept for binary compatibility but marked as deprecated since 2.14.0
    • Users should use CommutativeApplicative instead
  2. Added CommutativeApplicative as the primary implicit

    • ZipLazyList now provides catsDataCommutativeApplicativeForZipLazyList as the non-deprecated instance
    • ZipStream now provides catsDataCommutativeApplicativeForZipStream as the non-deprecated instance
    • This aligns with ZipVector which only has CommutativeApply
  3. Updated tests

    • Modified test suites to explicitly use the non-deprecated CommutativeApplicative instance
    • Tests now pass without deprecation warnings when using the correct instance

Background

The Alternative instance for ZipLazyList and ZipStream was found to be unlawful.
The combineK method used concatenation semantics from the underlying LazyList/Stream,
which is inconsistent with the zipping behavior of ap. This violates the Alternative
right distributivity law:

((ff |+| fg).ap(fa)) <-> ((ff.ap(fa)) |+| (fg.ap(fa)))

This also affects OneAnd[ZipLazyList, *] which cannot have a lawful Applicative
instance when the underlying F has an unlawful Alternative.

image

@satorg
Copy link
Contributor

satorg commented Mar 11, 2026

@LSUDOKO thank you for your effort!
Unfortunately it doesn't fix #4840, but rather attempts to fix #4830, and it does it rather incorrectly.
Besides, I'm working on #4830 already.

@armanbilge
Copy link
Member

armanbilge commented Mar 11, 2026

@LSUDOKO in typelevel/gsoc-onboarding#47, you agreed to follow the Typelevel GSoC AI Policy.

  1. Your PR doesn't address the referenced issue.
  2. Your code is not correct, and innapropriately modifies our test suite to work around its shortcomings.
  3. The description is very long and seems to be AI-generated.

Per our policy, we will not review low-quality and/or AI-generated PRs. It is disrespectful of our time and effort.

Thus, I will close your PR at this time.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Applicative[OneAnd[ZipLazyList, *]] works incorrectly

3 participants