Kotlin is a first class language for developing Android Apps. Kotlin port of cats will be a good library to use in android apps.
Kotlin has no support for typeclasses and HKT
Check out kategory, it's the closest you'll get ;)
Kategory seems to get a lot of commits from @raulraja who is also a big Cats contributor :-)
@arjunswaj Kategory started effectively as a cats port and has now deviated a bit on design to adjust it to Kotlin's ecosystem. We support Typeclasses, monadic comprehensions generalized to all monads and optionally stacksafe comprehensions for non stacksafe monads, cartesian builder and impls of many typeclasses and datatypes as the ones in Cats.
As part of the work we've done in Kategory we are gonna propose HKTs/Typeclasses for Kotlin but even emulating them you can write fully polymorphic code.
We also have modules with preliminary versions of effects with IO etc. and just started encoding recursion schemes. Feel free to swing by the Kotlin slack channel where we hang out and if you'd like to help we welcome contributors! Thanks! https://kotlinlang.slack.com/messages/C5UPMM0A0/
@raulraja
monadic comprehensions generalized to all monads
How did you do that without HKT? Defunctionalisation like in lightweight higher-kinded polymorphism?
@SystemFw yes and built on top of Kotlin coroutines:
This is what the encoding currently looks like:
HKs emulation:
https://github.com/kategory/kategory/blob/master/kategory-annotations/src/main/java/kategory/hks.kt
HKs typealiases boilerplate geenration:
https://github.com/kategory/kategory/blob/master/kategory-annotations-processor/src/main/java/kategory/higherkinds/HigherKindsFileGenerator.kt
Typeclasses: https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/Monad.kt#L12
Deriving Instances automatically based on naming conventions and presence of methods on receivers:
https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/data/Option.kt#L10
Manual instances: https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/instances/OptionTInstances.kt#L3
Monad bind in comprehensions expressed as suspension in corutines:
https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/Monad.kt#L59
And examples of usage in polymorphic code:
https://github.com/kategory/kategory/blob/master/kategory-test/src/main/kotlin/kategory/laws/MonadLaws.kt#L74
the biggest issue right now is lack of implicits but we have found a way to support implicits even for higherkinds with codegen and default args using an annotation processor. For now they are runtime based but this will change in the next couple of months.
Thanks for the reply. I don't really like or use Kotlin, but I sure do like me a nice bag of tricks :)
I've seen the do notation as coroutines in javascript as well, quite nifty
Based on the information in https://github.com/typelevel/cats/issues/1911#issuecomment-329454556 I'm going to go ahead and close this out. It sounds like Kategory is the answer here, as a direct port of Cats isn't feasible/practical in Kotlin.
Most helpful comment
@SystemFw yes and built on top of Kotlin coroutines:
This is what the encoding currently looks like:
HKs emulation:
https://github.com/kategory/kategory/blob/master/kategory-annotations/src/main/java/kategory/hks.kt
HKs typealiases boilerplate geenration:
https://github.com/kategory/kategory/blob/master/kategory-annotations-processor/src/main/java/kategory/higherkinds/HigherKindsFileGenerator.kt
Typeclasses: https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/Monad.kt#L12
Deriving Instances automatically based on naming conventions and presence of methods on receivers:
https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/data/Option.kt#L10
Manual instances: https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/instances/OptionTInstances.kt#L3
Monad bind in comprehensions expressed as suspension in corutines:
https://github.com/kategory/kategory/blob/master/kategory-core/src/main/kotlin/kategory/typeclasses/Monad.kt#L59
And examples of usage in polymorphic code:
https://github.com/kategory/kategory/blob/master/kategory-test/src/main/kotlin/kategory/laws/MonadLaws.kt#L74
the biggest issue right now is lack of implicits but we have found a way to support implicits even for higherkinds with codegen and default args using an annotation processor. For now they are runtime based but this will change in the next couple of months.