-
Notifications
You must be signed in to change notification settings - Fork 357
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
WIP: Support for fs2.Task dropping own Catchable #323
Conversation
| implicit val Catchable${sname}IO: Catchable[${sname}IO] = | ||
| new Catchable[${sname}IO] { | ||
| def attempt[A](f: ${sname}IO[A]): ${sname}IO[Throwable \\/ A] = ${sname.toLowerCase}.attempt(f) | ||
| def fail[A](err: Throwable): ${sname}IO[A] = ${sname.toLowerCase}.delay(throw err) | ||
| } | ||
|#-scalaz | ||
|#+cats | ||
|#+fs2 |
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 think cats
directive is unnecessary here. Right?
c31ad0b
to
531df0e
Compare
The second commit is slightly out of scope. I just found unnecessary diffs caused by varying method order with environments annoying. |
Yeah the ever-changing codegen is irritating. I will look at this more closely this weekend. It seems like a big change but it certainly makes sense to get rid of our own |
I have been struggling to combine |
FWIW, I think we could introduce the following to FS2: trait Suspendable[F[_]] extends Monad[F] {
def suspend[A](fa: => F[A]): F[A]
def delay[A](a: => A): F[A]
}
trait Effect[F] extends Catchable[F] with Suspendable[F] {
def unsafeRunAsync[A](fa: F[A])(cb: Attempt[A] => Unit): Unit
} |
@mpilquist That's perfect, I managed to write a modified version having every |
@guersam thanks for your continued hacking on this. I didn't have any time over the weekend to get into it but I will catch up soon. |
@tpolecat No problem, and sorry about some inessential diffs which will make the review harder. As noted above I didn't expect the changes to be this huge 😨 |
This PR moves `suspend` and `delay` from the `Effect` type class to a new `Suspendable` type class. There are two motivations for doing this: - Exposing `unsafeRunAsync` to any function that requires `suspend` or `delay` gives up a lot of parametricity. - Some type constructors have `Suspendable` instances but do not support value extraction. This came up in the [port of Doobie to FS2](typelevel/doobie#323 (comment)). This [came up on Gitter a while back as well](http://www.gitterforum.com/discussion/scalaz-scalaz-stream?page=143).
Ok, so here are a few thoughts.
This is really irritating because scalaz
👍
My instinct is to support only cats typeclasses, with the exception of fs2's So I'm wondering if this is too much to do for 0.3.1 … I was kind of thinking of just providing instances for fs2 |
Sounds reasonable. A little thought about cats/fs2 typeclass support:
Breaking the changes smaller for 0.3.1 will also be fine. Although there's no official release for cats/fs2 yet, there's good reason for keep migration steps small enough. In my case, there are actually no big differences since I'm not using the APIs lower than |
BTW, is there a reason for the lack of automatic |
I think there was a reason but I don't remember. Opened #329 to follow up. So for 0.3.1 maybe do the following and push off generalizing support for fs2 typeclasses
I really doubt we will get any actual cats+fs2 users since both libraries are in so much flux at the moment, so I think we have time to generalize later. I'd just like to get a release out that people can play with. What do you think? |
Agreed. I'm willing to port to my scalaz-stream codebase to cats/fs2 to get rid of mixed imports from scalaz and cats. I'll handle #329 first and then add missing instances for |
After second trial, I still find it harder than expected to add a few In this nature, it's getting more and more natural to me to fully support |
Ok, I will take a look tomorrow and see if I run into the same issue. |
- Sort ctors using the arguments as well as the name - Convert `java.lang.Object` to `scala.AnyRef`
a684516
to
85b0a27
Compare
I don't know how to flush the cache but I restarted that build. |
Cache settings will appear in the travis repo page: https://docs.travis-ci.com/user/caching/#Clearing-Caches Tried to do this by myself but I don't have the permission. Wish that travis allows PR openers to clear their PR specific cache. |
Ah ok, thanks. Cleared and restarted the build. |
Looks like it worked. |
Thanks :) On Wed, Aug 24, 2016, 9:14 AM Rob Norris notifications@github.com wrote:
|
@@ -152,17 +154,17 @@ class FreeGen(managed: List[Class[_]], log: Logger) { | |||
// Ctor values for all methods in of A plus superclasses, interfaces, etc. | |||
def ctors[A](implicit ev: ClassTag[A]): List[Ctor] = | |||
methods(ev.runtimeClass).groupBy(_.getName).toList.flatMap { case (n, ms) => | |||
ms.toList.zipWithIndex.map { | |||
ms.toList.sortBy(_.getGenericParameterTypes.map(toScalaType).mkString(",")).zipWithIndex.map { |
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.
Thanks for this change, I should have done this a long time ago. Stuff was getting shuffled around every time I ran freegen.
Ok, I think this looks great. Huge amount of work. I'm fine with Is there anything else that needs to be done in this PR before merging? I'd prefer to get this in and then follow up as needed rather than keep this open longer. What do you think? |
I would hold off on adding the |
@adelbertc thanks, that was my instinct too. Given the volatility we should do the simplest thing that works. |
Although some docs (especially the book) should be updated to catch up these changes, I'd like merging this for now too. |
Alright let's do it. |
How does this work with
|
@macalinao You will need to define an instance of trait Catchable[F[_]] extends Monad[F] {
/** Lifts a pure exception in to the error mode of the `F` effect. */
def fail[A](err: Throwable): F[A]
/** Provides access to the error in `fa`, if present, by wrapping it in a `Left`. */
def attempt[A](fa: F[A]): F[Attempt[A]]
} |
You'll need instancs of |
I see, thanks. For future readers, here's my typeclass: implicit object taskCatchable extends Catchable[Task] with Suspendable[Task] {
def pure[A](a: A): Task[A] = Task.pure(a)
def flatMap[A, B](a: Task[A])(f: A => Task[B]): Task[B] =
a.flatMap(f)
def fail[A](err: Throwable): Task[A] =
Task.raiseError(err)
def attempt[A](fa: Task[A]): Task[Attempt[A]] =
fa.materialize.map(_.toEither)
def suspend[A](fa: => Task[A]): Task[A] =
Task.suspend(fa)
} |
An attempt to fix #311.
Although I didn't mean to touch all these stuff at first, eventually I ended up with dropping
doobie.util.catchable.Catchable
in favor offs.util.Catchable
fighting a lot of ambiguous implicit errors. But probably there would be a much simpler way...Changes made (which can be reverted) or things to discuss:
cats.data.Xor
withscala.util.Either
to supportfs2.util.Catchable
(related discussion: data.Xor and instances/either.scala: Either is now right-biased cats#1192)fs2.util.Suspendable
instead ofCapture[fs2.Task]
Or revivedoobie.util.catchable.Catchable
and directly support only forfs2.Task
?DropIOLite
?fs2.util.Suspendable
instance forcats.data.Kleisli
into fs2-catsTODO: