arrow-kt / arrow Goto Github PK
View Code? Open in Web Editor NEWΛrrow - Functional companion to Kotlin's Standard Library
Home Page: http://arrow-kt.io
License: Other
Λrrow - Functional companion to Kotlin's Standard Library
Home Page: http://arrow-kt.io
License: Other
¡Me lo pido!
Now that there's a solution for type lambdas, we can implement the rest of the composed typeclasses
Our solution:
https://github.com/kategory/kategory/blob/master/kategory/src/main/kotlin/kategory/data/Composed.kt
Cats reference:
https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Composed.scala
It's common to stack overflow if instances of Monad for example don't provide overrides that delegate to the Datatype impl which is usually the shortest and more efficient path.
For example when creating an instance for Monad
and your datatype contains map
, ap
and others, do not let the methods in the Monad hierarchy to stay autoimplemented and provide instead overrides that delegate to the datatype because the default implementations are usually non-effitient and can lead to stack overflow errors.
For example Monad implements ap
in terms of flatMap
, and Applicative implements map
in terms of ap
. While this may be ok for simple datatypes it's gonna blow up in cases such as EitherT and other more complex ones.
Each datatype should have separate classes for each instance it implements for example. Instead of having a single IdMonad
we should have IdMonad: IdApplicative
and IdApplicative: IdFunctor
and so on where in each class there is a delegation of the corresponding methods to the ones present in the datatype.
Rename swap() to reverse() and implement for all tuples.
Convert toT into plus.
Jitpack is not doing snapshot deploys properly due to incremental compilation errors. If any one has experienced this problem lately and knows how to force disable it for Jitpack, that would be helpful.
Snapshots are important also and enables anybody (not just us) to test the library on different projects and give good feedback.
I attach brand assets in PNG and SVG format
kategory-assets.zip
Following problems reported on #105, we need to find the way to avoid the requirement for holding a reference of any implicit instance prior to make it work as an implicit inside any class, and not crash at runtime. Check the linked issue for more details.
This document is a brain dump from the stuff I've been working on lately around data types. Instances to come on a separate issue.
Example: https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/WriterT.kt
The file reads as follows:
package katz // we want all imports together for now
typealias MyTypeKind<...> = HK_N_<MyType.F, ...> // This defines the higher kind this type belongs to. N is the number of parameters in ...
typealias MyTypeF<...> = HK_N - 1_<MyType.F, ...> // A partially applied type generally used for typeclass instances
Here we use extension methods parametrized on generics to add functionality to specific types. This is a cool kotlin-exclusive feature you need to familiarize with. It has the advantage of not forcing inheritance, and they're found by the compiler using a type lookup. If you try to use it on a tag type you haven't defined for, you'll get a very verbose error message to tell you the lookup failed.
fun <A, B> MyTypeKind<...>.ev(): MyType<...> = this as MyType<...> // This brings the higher kind back into the implementation using a safe unchecked cast
fun MyTypeKind.value(): A = this.value // For simple wrappers types like Id this helper can be added to retrieve the value
data class MyType<...>(val ...): MyTypeKind<...>
Data class to get equals and hashCode. Some data types may require using a sealed class instead, like Either or Optional do.
Use the kind typealias for the HK tag.
class F private constructor()
This type cannot be instanced and is used exclusively in higher kinds to enable .ev() to be inferred correctly
The companion object's duty is to hold all the smart constructors for the variations of the type. Provide at least one that'll correspond to pure() for the monad.
One common pattern used for smart constructors is overloading the invoke operator. The operator can be inlined, which enables reified generics. With reified generics, you can call the methods used for global injection of typeclass instances. This methods are named after the typeclass, so you can use monad(), foldable(), applicable()...
TEMPORARY HACK. ONLY AVAILABLE FOR NON-PARAMETRIZED INSTANCES:
Example: https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/NonEmptyList.kt#L62
GlobalInstance<A: Typeclass> is a helper that takes the Typeclass defined by A and adds it to a global map. This makes it available to be found using the global injection functions like monad() or functor().
Generally recommended to implement map and flatMap here. Other useful methods are fold, foldr/foldl, traverse, extract, and coflatMap.
These will be used by the typeclass instances directly, and can be enhanced from the required canonical implementation.
When need something similar to Discipline in order to test category laws (example)
Fix repository name in Travis changing it from kats
to Katz
StateT has no tests available
Create a mapOf function to build a Map from Tuple2 as the mapOf (in kotlin-stdlib) builds a Map from Pair
Our tuples are not capable of destructuring at the moment.
Destructuring is based off nomenclature, where every parameter gets a function componentX() where X is the position of the component.
Reference:
https://kotlinlang.org/docs/reference/multi-declarations.html
As per #69
What about introducing the lib in travis?
Taking this one because I've never looked into the writer monad so, yeah.
This implementation will be a simplification as we don't have HKTs yet
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/NonEmptyList.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListBimonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListMonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListComonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListSemigroup.kt
See the comments at the bottom of #120
Since the coroutine system allows us to invoke resume
when we want the coroutine to proceed we could potentially exploit that so that if the user indicates that he wants the monadic comprehension to be stack safe even if the underlying monad is not stacksafe we could explicitly trampoline before calling resume
. from a usage point of view it would be transparent to the user and it would be just an extra param to the binding block:
Option.binding(StackSafe) {
...
}
Kleisli has no instances
Traverse
needs to be done in terms of Foldable
, so we need to wait for #62 to be done.
They're necessary to complete the Traverse laws after #133
Nested: https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/data/Nested.scala
And the traverse law that requires Nested: https://github.com/typelevel/cats/blob/master/laws/src/main/scala/cats/laws/TraverseLaws.scala#L16
https://github.com/kategory/kategory/pull/133/files#diff-8ad20c0b396ad4072dcdf3c16dafafaaR23
--
Const: https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/data/Const.scala
Add traverse law that requires Const:
https://github.com/typelevel/cats/blob/master/laws/src/main/scala/cats/laws/TraverseLaws.scala#L61-L68
https://github.com/kategory/kategory/pull/133/files#diff-8ad20c0b396ad4072dcdf3c16dafafaaR26
Continuation from #101.
Missing tests:
Validated
Coproduct
Either
OptionT
Ior
Try
Id
Laws:
https://github.com/typelevel/cats/blob/master/laws/src/main/scala/cats/laws/FoldableLaws.scala
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/NonEmptyList.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListBimonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListMonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListComonad.kt
https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/instances/NonEmptyListSemigroup.kt
It'll also require a Monoid instance, rather than a semigroup. You have to figure out why and how ;)
Eval
type is being created under this PR also since its needed for Foldable
.
There is a good chance of experimenting integration with existing apps and frameworks, and RxJava seems like a natural fit. We're looking for someone to take on the following subtasks:
The estimated effort is around 500-700 lines of code. The maintainers compromise to help and support whomever is completing this ticket, as it'll help assess the difficulty of applying the concepts for newcomers.
As per #31 there are three possible approaches to comprehensions:
optionMonad.binding {
val a = bind { monad }
val b = monad.bind()
val c = ! monad
yields { a + b + c }
}
After the library has been in prod, and if widespread, consider elimination at least one of the options based off usage.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.