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 Alternative, Bifoldable, and MonadCombine #261

Merged
merged 25 commits into from
Sep 13, 2017
Merged

Conversation

JorgeCastilloPrz
Copy link
Member

@JorgeCastilloPrz JorgeCastilloPrz commented Sep 10, 2017

Fixes #257 and #248 (very related)

  • Added AlternativeLaws
  • Added MonadCombine
  • Added MonadCombineLaws
  • Added Bifoldable
  • Added BifoldableLaws
  • Tested MonadCombineLaws and AlternativeLaws using a stateT monadCombine instance.
  • Tested BifoldableLaws using an instance of ComposedBifoldable.
  • Segregated StateT instances to avoid asking for not needed dependencies on each one of them. This also allowed to add two new ones: StateTMonadCombine and StateTMonadError.

@codecov-io
Copy link

codecov-io commented Sep 10, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@2c84602). Click here to learn what that means.
The diff coverage is 29.06%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #261   +/-   ##
========================================
  Coverage          ?   45.3%           
  Complexity        ?     319           
========================================
  Files             ?     149           
  Lines             ?    3803           
  Branches          ?     423           
========================================
  Hits              ?    1723           
  Misses            ?    1946           
  Partials          ?     134
Impacted Files Coverage Δ Complexity Δ
...t/src/main/kotlin/kategory/laws/MonadFilterLaws.kt 7.14% <ø> (ø) 1 <0> (?)
...src/main/kotlin/kategory/laws/FunctorFilterLaws.kt 5.55% <ø> (ø) 1 <0> (?)
.../src/main/kotlin/kategory/generators/Generators.kt 48.78% <0%> (ø) 0 <0> (?)
...c/main/kotlin/kategory/typeclasses/MonadCombine.kt 0% <0%> (ø) 0 <0> (?)
...egory-core/src/main/kotlin/kategory/data/ListKW.kt 88.23% <0%> (ø) 11 <0> (?)
...rc/main/kotlin/kategory/typeclasses/Alternative.kt 0% <0%> (ø) 0 <0> (?)
...src/main/kotlin/kategory/typeclasses/Bifoldable.kt 33.33% <33.33%> (ø) 0 <0> (?)
...egory-core/src/main/kotlin/kategory/data/StateT.kt 57.89% <33.33%> (ø) 8 <0> (?)
.../main/kotlin/kategory/instances/StateTInstances.kt 67.44% <46.15%> (ø) 0 <0> (?)
...st/src/main/kotlin/kategory/laws/BifoldableLaws.kt 5.26% <5.26%> (ø) 1 <1> (?)
... and 4 more

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 2c84602...96a1cec. Read the comment docs.

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

Outstanding work 👏 👏 awesome to see more typeclasses we initially thought impossible coming into Kategory 🎉 . Let's update this branch with master's new style. There are new tests to make sure the declared implicit typeclasses work implcitly that you would have to add to all the new instances once you get latest from master.

@@ -1,7 +1,7 @@
package kategory

@higherkind
@deriving(Monad::class, Traverse::class, MonoidK::class)
@deriving(Monad::class, Traverse::class, MonoidK::class, MonadCombine::class)
Copy link
Member

Choose a reason for hiding this comment

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

To be consistent with the rest of typeclasses in and derived instances we should here list all of the instances individually... Functor, Applicative, Monad, SemigroupK, MonoidK,...

@@ -5,7 +5,8 @@ typealias StateTFunKind<F, S, A> = HK<F, StateTFun<F, S, A>>

fun <F, S, A> StateTKind<F, S, A>.runM(initial: S): HK<F, Tuple2<S, A>> = (this as StateT<F, S, A>).run(initial)

@higherkind class StateT<F, S, A>(
@higherkind
class StateT<F, S, A>(
Copy link
Member

Choose a reason for hiding this comment

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

The ones currently in master merged in #264 already include the refactoring for StateT that is consistent in naming conventions and implementations with the rest of the code base. You can accept master changes when updating this branch.

@@ -1,25 +1,28 @@
package kategory

import kategory.Option.None
import kategory.Option.Some

interface OptionMonoid<A> : Monoid<Option<A>> {
Copy link
Member

Choose a reason for hiding this comment

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

Same as mentioned for StateT the ones in master have been already addressed

}
is Option.None -> a
is None -> a
}

}

data class OptionMonadError<E>(val error: E) : MonadError<OptionHK, E> , OptionMonadInstance {
Copy link
Member

Choose a reason for hiding this comment

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

Same as mentioned for StateT the ones in master have been already addressed

fun F(): Monad<F>
fun G(): SemigroupK<F>

override fun <A> combineK(x: HK<HK2<StateTHK, F, S>, A>, y: HK<HK2<StateTHK, F, S>, A>): StateT<F, S, A> =
StateT(F(), F().pure({ s -> G().combineK(x.ev().run(s), y.ev().run(s)) }))
}

interface StateTMonadCombine<F, S> : MonadCombine<StateTKindPartial<F, S>>, StateTMonad<F, S>, StateTSemigroupK<F, S> {
Copy link
Member

Choose a reason for hiding this comment

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

This instance requires an implicit object as introduced by #264

@@ -0,0 +1,16 @@
package kategory

interface Bifoldable<in F> : Typeclass {
Copy link
Member

Choose a reason for hiding this comment

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

Contravariant in positions don;t work currently in the implicits system because java reflection does not see those how we need them to lookup instances by type so we should remove in positions from typeclasses.

@@ -0,0 +1,16 @@
package kategory

interface Bifoldable<in F> : Typeclass {
Copy link
Member

Choose a reason for hiding this comment

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

Most datatypes that currently support Bimonad and Foldable are probably gonna be able to implement this typeclass.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which ones ?


import io.kotlintest.properties.forAll

object BifoldableLaws {
Copy link
Member

Choose a reason for hiding this comment

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

👏

@JorgeCastilloPrz
Copy link
Member Author

Everything is rebased / fixed / following your typeclass instances derivation system. I think I didn't miss anything so please, take another look when you have a moment @raulraja.

@JorgeCastilloPrz JorgeCastilloPrz changed the title Add Alternative, Bifoldale, and MonadCombine Add Alternative, Bifoldable, and MonadCombine Sep 13, 2017
@raulraja
Copy link
Member

Excellent!

@raulraja raulraja merged commit ce0e13b into master Sep 13, 2017
@raulraja raulraja deleted the jorge-monadcombine branch September 13, 2017 16:13
@wiyarmir wiyarmir mentioned this pull request Sep 15, 2017
rachelcarmena added a commit that referenced this pull request Feb 24, 2021
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.

3 participants