-
Notifications
You must be signed in to change notification settings - Fork 455
Add divide typeclasses #1311
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 divide typeclasses #1311
Conversation
Hmm I don't think I understand the error ank throws here. It happens locally as well, but not when the code is just run in a standalone file (copy pasted over basically). I am confused :/ |
I'll review this tonight or tomorrow! |
cf: (Int) -> Kind<F, Int>, | ||
EQ: Eq<Kind<F, Int>> | ||
): Unit = | ||
forAll(Gen.int().map(cf)) { fa -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cute. I like it :)
EQ: Eq<Kind<F, Int>> | ||
): Unit = | ||
forAll(Gen.int().map(cf)) { fa -> | ||
EQ.run { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should use equalsUnderTheLaw
instead of EQ
directly.
EQ: Eq<Kind<F, Int>> | ||
): Unit = | ||
forAll(Gen.int().map(cf)) { fa -> | ||
EQ.run { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, equalsUnderTheLaw
* | ||
* fun main(args: Array<String>) { | ||
* //sampleStart | ||
* val stringOrInt: Serializer<Either<String, Int>> = Serializer.decidable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Powerful shit.
fh: Kind<F, H>, | ||
fi: Kind<F, I>, | ||
fj: Kind<F, J>, | ||
f: (Z) -> Either<A, Either<B, Either<C, Either<D, Either<E, Either<FF, Either<G, Either<H, Either<I, J>>>>>>>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raulraja is there any way of generalizing this for Product? Or convert between them?
/** | ||
* [Divide] is a typeclass that models the divide part of divide and conquer. | ||
* | ||
* [Divide] basically states: Given a Kind<F, A> and a Kind<F, B> and a way to turn C into an A and B it gives you a Kind<F, C> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
into an A and B
may be better phrased as a tuple of A and B
, even if it's an implementation detail it's easy to miss.
val (a, b, c, d, e, fff, g, h, i, j) = f(it) | ||
a toT Tuple9(b, c, d, e, fff, g, h, i, j) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: additional empty line
dummy6: Unit = Unit, | ||
dummy7: Unit = Unit, | ||
dummy8: Unit = Unit | ||
): Kind<F, Tuple10<A, B, C, D, E, FF, G, H, I, J>> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIP IntelliJ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done worse with a small project regarding generators for prop testing (generated ~1k lines of Tuple code for generating tuples and shrinkers for them) :) IntelliJ takes a while to load that file :D
beginner | ||
|
||
`Divide` is a typeclass that models the divide part of divide and conquer. | ||
`Divide` basically states: Given a `Kind<F, A>` and a `Kind<F, B>` and a way to turn `C` into an `A` and `B` it provides you a `Kind<F, C>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, mention a coproduct or a tuple or something that helps with the association, else it's easy to miss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good job getting both parts of the hierarchy! 👏
Approving to unblock, but I'd like to see the fixes in the laws if possible.
WTF github I never clicked that |
Done the small stuff. |
Added a test for Sum. Now only StateT is missing, but since we have no instance that is Monad and Divisible that is kinda hard to do. (Function1 is almost it with |
So ank is being funny (or rather what executes the script). The code 100% compiles and runs fine but running in ank crashes with: |
Do you know what file is that for? |
The scary internal error is for Decidable's README and the other type inference error happens for all snippets where Serializer's contramap is defined without this@contramap (every snippet in kdoc for divide etc) |
I'd move the setup code to the arrow-docs project instead. You'll probably get codegen right with it too. |
Yeah this fixed it. Too bad the examples now cannot be viewed in full, but better than no examples at all |
@@ -0,0 +1,44 @@ | |||
package com.example.domain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1Jajen1 I didn't see this before merging. Could you please make it a nicer package?
Partially solves #284 (Only the divide parts)
Again like stated in #1181 there some annoying parts:
Any ideas for better examples/texts do describe them? I'll think about it some more, but don't know if I can come up with something better :/