Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateT no longer violates laws #1735

Merged
merged 3 commits into from
Jun 20, 2017
Merged

Conversation

djspiewak
Copy link
Member

Closes #1714

Fixes the issues uncovered by @ceedubs. After a fair bit of digging, I'm relatively confident that the issues in question are stemming from the inconsistencies (but not unlawfulness) of deriving Applicative instances from nested type constructors (inconsistent relative to analogous monadic derivation). My arguments on #1714 were overbroad and unsupported, and further digging showed that they don't hold in general (which is good!).

So I think we're good with StateT in its current formulation. At least, in so far as I can tell. The tests are now passing. This does break the API though, since certain functions are removed from StateT and now once again only available implicitly.

ceedubs and others added 3 commits May 31, 2017 21:39
As pointed out [here](typelevel#1640 (comment))

This reveals law violations in `StateT`. It looks like `flatMap`/`ap`
consistency does not hold, as well as `MonadCombine`
right-distributivity. It's not immediately clear to me how to fix this,
so I'm opening this up in case somebody else gets to it first.
@ceedubs
Copy link
Contributor

ceedubs commented Jun 20, 2017

Thanks @djspiewak! I was feeling very uneasy about this.

It seems like it would be nice to have a map2Eval implementation that were lazier (for F types that support laziness), but I guess I don't even know whether that's possible. And (assuming the build passes), this definitely seems like an improvement over unlawful implementations. 👍

@codecov-io
Copy link

codecov-io commented Jun 20, 2017

Codecov Report

Merging #1735 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1735      +/-   ##
==========================================
- Coverage   94.03%   94.01%   -0.03%     
==========================================
  Files         252      252              
  Lines        4189     4175      -14     
  Branches      154      154              
==========================================
- Hits         3939     3925      -14     
  Misses        250      250
Impacted Files Coverage Δ
core/src/main/scala/cats/data/StateT.scala 96.87% <ø> (-0.57%) ⬇️
...rc/main/scala/cats/laws/discipline/Arbitrary.scala 90.47% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca7c8c0...2868cba. Read the comment docs.

Copy link
Contributor

@kailuowang kailuowang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for delving this through @djspiewak

@djspiewak
Copy link
Member Author

Merging with two sign-offs.

@djspiewak djspiewak merged commit 2868cba into typelevel:master Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants