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

#500 add derived foldMap from traverse law #502

Merged
merged 6 commits into from
Sep 15, 2015
Merged

#500 add derived foldMap from traverse law #502

merged 6 commits into from
Sep 15, 2015

Conversation

julien-truffaut
Copy link
Contributor

I probably missed something in the definition of the law because they all pass but a simple test shows that it is not the case for List

@julien-truffaut
Copy link
Contributor Author

@non could it be related to the limitation of Arbitrary function you mentioned recently?

@julien-truffaut
Copy link
Contributor Author

Traverse laws still pass with non commutative Monoid. If I understand correctly it is because because the arbitrary instance of Function only generates constant function

@non
Copy link
Contributor

non commented Sep 1, 2015

@julien-truffaut Correct. Once we have a new ScalaCheck release we will start getting real functions which actually depend on their input.

@julien-truffaut
Copy link
Contributor Author

@non so what do you recommend to do?

  • commit new law (remove unit test in List) and wait for scalacheck upgrade to fix instances
  • commit new law and try to fix as many instances as possible
  • something else?

@non
Copy link
Contributor

non commented Sep 2, 2015

@julien-truffaut I guess I would say we should do (1). To me that seems like the best path, and will avoid duplicate (or redundant) work. But I'm fine with any of these to be honest.

@julien-truffaut
Copy link
Contributor Author

I went for (2) but only List, Vector and Stream (I need them for monocle test to pass).

I could fix List and Vector, we can probably have more efficient impl for Vector. However, I am struggling with Stream, I wouldn't mind if someone else would like to give it a try.

@non
Copy link
Contributor

non commented Sep 5, 2015

OK, I'll take a look.

@ceedubs
Copy link
Contributor

ceedubs commented Sep 6, 2015

@julien-truffaut I was perplexed by the discrepancy between the traverse/const and foldMap for List, and I realized that our implementation of ap for Const is the reverse of what is in scalaz. Are you aware of that? At first glance, both implementations appear to satisfy the necessary laws to me, but I could definitely be mistaken.

Cats:

scala> val x = Const[List[Int], String](List(1)) ap Const[List[Int], String => String](List(2))
x: cats.data.Const[List[Int],String] = Const(List(1, 2))

Scalaz:

scala> val x = Const[List[Int], String](List(1)) <*> Const[List[Int], String => String](List(2))
x: scalaz.Const[List[Int],String] = Const(List(2, 1))

@non
Copy link
Contributor

non commented Sep 6, 2015

@ceedubs I also noticed some interesting order issues in the monoidal branch I'm working on.

@aryairani
Copy link
Contributor

flashback to #142

@julien-truffaut
Copy link
Contributor Author

@ceedubs no I didn't notice. It seems that haskell use the same order than cats http://hackage.haskell.org/package/base-4.8.1.0/docs/src/Control.Applicative.html#line-84

@ceedubs
Copy link
Contributor

ceedubs commented Sep 7, 2015

@julien-truffaut I think Haskell's is actually the opposite of Cats. It looks the same because the value from the first const is "prepended" to the value from the second const. However, the function argument comes first in Haskell while it comes second in Cats. I think that it makes sense to have the function come first in Haskell but last in Scala, due to differences in the languages. However, it does mean that the version of Const.ap that we would probably want for traverse would probably seem backwards if used by itself. I suspect this might become a non-issue if @non's monoidal work replaces ap (though I'm not sure - the plan might be to leave it in).

@julien-truffaut
Copy link
Contributor Author

@ceedubs maybe I missed something but it seems to me that haskell behave in the same way than cats

Prelude Control.Applicative Data.Monoid> Const(3 : []) <*> Const(5 : [])
Const [3,5]

@julien-truffaut
Copy link
Contributor Author

some additional background of scalaz impl: scalaz/scalaz@084e9c9#commitcomment-13182666

@julien-truffaut
Copy link
Contributor Author

@ceedubs found out exactly what was the issue!

@codecov-io
Copy link

Current coverage is 65.09%

Merging #502 into master will increase coverage by +0.01% as of 01d807b

@@            master    #502   diff @@
======================================
  Files          156     156       
  Stmts         2417    2418     +1
  Branches        68      68       
  Methods          0       0       
======================================
+ Hit           1573    1574     +1
  Partial          0       0       
  Missed         844     844       

Review entire Coverage Diff as of 01d807b

Powered by Codecov. Updated on successful CI builds.

@non
Copy link
Contributor

non commented Sep 15, 2015

👍

@non
Copy link
Contributor

non commented Sep 15, 2015

Sorry for the new merge conflicts. If this gets updated I'm happy to see it merged. Thanks!

@adelbertc
Copy link
Contributor

👍 from me once merge conflicts resolved (and Travis is green light)

@ceedubs
Copy link
Contributor

ceedubs commented Sep 15, 2015

What @adelbertc said ^

non added a commit that referenced this pull request Sep 15, 2015
#500 add derived foldMap from traverse law
@non non merged commit c63e0a5 into master Sep 15, 2015
@non non removed the ready label Sep 15, 2015
@non non deleted the traverse_fold branch April 28, 2016 03:52
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.

7 participants