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

Add some more OptionT instances. #1103

Merged
merged 3 commits into from
Jun 15, 2016

Conversation

peterneyens
Copy link
Collaborator

@peterneyens peterneyens commented Jun 9, 2016

  • Added Eq, PartialOrder and Order.
  • Added Semigroup and Monoid.
  • Added SemigroupK and MonoidK
  • Added MonadError, MonadCombine and MonadFilter (the last two
    instances are dissabled, because they violate the same laws as the
    equivalent XorT instances).

@codecov-io
Copy link

codecov-io commented Jun 9, 2016

Current coverage is 88.78%

Merging #1103 into master will increase coverage by 0.15%

  1. 2 files (not in diff) in ...main/scala/cats/data were modified. more
    • Misses -1
    • Hits +1
  2. 2 files (not in diff) in .../src/main/scala/cats were modified. more
    • Misses -1
    • Hits +1
@@             master      #1103   diff @@
==========================================
  Files           227        227          
  Lines          2946       2968    +22   
  Methods        2890       2910    +20   
  Messages          0          0          
  Branches         53         56     +3   
==========================================
+ Hits           2611       2635    +24   
+ Misses          335        333     -2   
  Partials          0          0          

Sunburst

Powered by Codecov. Last updated by b149835...2183b75

@peterneyens peterneyens force-pushed the optiont-instances branch 2 times, most recently from 7ba501a to 67c7f39 Compare June 10, 2016 11:02

implicit val monadError = OptionT.catsDataMonadErrorForOptionT[SXor, String]

// checkAll("OptionT[String Xor ?, Int]", MonadErrorTests[OptionT[SXor, ?], String].monadError[Int, Int, Int])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need an Arbitrary[λ[(α, β) => OptionT[String Xor α, β]]] which I don't seem to get from the Arbitrary instances of Xor and OptionT.

I need to figure how to create this instance and if it has a place in laws.discipline.arbitrary.

@peterneyens
Copy link
Collaborator Author

peterneyens commented Jun 10, 2016

The only instances currently still missing which can added for OptionT are Semigroup and Monoid, if I'm correct.

I'm currently failing to provide an Arbitrary to run the MonadErrorTests (see my comment in the code). If some might have some pointers ... they would be greatly appreciated 😉.

I am also not sure why the partialOrder lines don't seem to have test coverage, I thought they were included in OrderLaws ?

@peterneyens peterneyens force-pushed the optiont-instances branch 2 times, most recently from 26a99a9 to bf91788 Compare June 10, 2016 20:57

implicit val iso = CartesianTests.Isomorphisms.invariant[OptionT[SXor, ?]]

checkAll("OptionT[String Xor ?, Int]", MonadErrorTests[OptionT[SXor, ?], String].monadError[Int, Int, Int])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MonadErrorTests is working now, but I had to supply all the Arbitrary and Eq instances myself, I don't know if there is a better way ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The better way is probably #1073 but let's hold off on that for this PR.

Added `Eq`, `PartialOrder`, `Order`.
Added `Semigroup`, `Monoid`
Added `SemigroupK`, `MonoidK`
Added `Foldable`, `Traverse`
Added `MonadError`, `MonadCombine` and `MonadFilter` (the last two
instances are dissabled, because they violate the same laws as the
equivalent XorT instances).

Rewrote the tests to use `ListWrapper`.
I used the ListWrapper methods added by @yilinwei in # 1106.
/* TODO violates right absorbtion, right distributivity, and left distributivity -- re-enable when MonadCombine laws are split in to weak/strong
implicit def catsDataMonadCombineForOptionT[F[_]](implicit F0: Monad[F]): MonadCombine[OptionT[F, ?]] =
new OptionTMonadCombine[F] { implicit val F = F0 }
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should probably track this (and the other below) with a GitHub issue instead of commented-out code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I followed the example of XorT to include them disabled.

Do I drop the implicit functions, the traits OptionTMonadFilter and OptionTMonadCombine and their tests ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@peterneyens that's what I'd be inclined to do. We always have git history if people want to pull them back out (and ideally the GitHub issue tracking this could link to the previous implementation).

@ceedubs
Copy link
Contributor

ceedubs commented Jun 11, 2016

Thanks a bunch @peterneyens, this is great!

I left a minor comment about commented-out code, but other than that 👍.

@xuwei-k
Copy link
Contributor

xuwei-k commented Jun 14, 2016

[error] /home/travis/build/xuwei-k/cats/tests/src/test/scala/cats/tests/OptionTTests.scala:12: ambiguous implicit values:
[error]  both method catsDataMonadForOptionT in trait OptionTInstances0 of type [F[_]](implicit F0: cats.Monad[F])cats.Monad[[β]cats.data.OptionT[F,β]]
[error]  and method catsDataMonadErrorForOptionT in trait OptionTInstances0 of type [F[_], E](implicit F0: cats.MonadError[F,E])cats.MonadError[[β]cats.data.OptionT[F,β],E]
[error]  match expected type cats.Monad[[β]cats.data.OptionT[scala.util.Try,β]]
[error]   Monad[OptionT[scala.util.Try, ?]]
[error]        ^
[error] one error found

@peterneyens
Copy link
Collaborator Author

@xuwei-k Thanks for pointing this out, I already found it kind of strange that this didn't give any problems and didn't really think this through.

implicit def catsDataMonadErrorForOptionT[F[_], E](implicit F0: MonadError[F, E]): MonadError[OptionT[F, ?], E] =
new OptionTMonadError[F, E] { implicit val F = F0 }

implicit def catsDataSemigroupK[F[_]](implicit F0: Monad[F]): SemigroupK[OptionT[F, ?]] =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want a forOptionT at the end of this name.

@ceedubs
Copy link
Contributor

ceedubs commented Jun 14, 2016

One more minor comment, then I think this is good to go!

Add a "test" to check the implicit resolution of OptionT instances.
@ceedubs
Copy link
Contributor

ceedubs commented Jun 14, 2016

👍

@kailuowang
Copy link
Contributor

This is awesome. LGTM 👍

@kailuowang kailuowang merged commit 8e1861d into typelevel:master Jun 15, 2016
@peterneyens peterneyens deleted the optiont-instances branch July 18, 2016 12:06
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.

5 participants