IO vs Task vs Future

1,173 views
Skip to first unread message

Ken Scambler

unread,
Jan 9, 2015, 12:12:40 AM1/9/15
to sca...@googlegroups.com
From reading the docs I see that Tasks build on Futures, adding error-handling functionality.  Is that the only difference between them that I should care about? 

What is the difference in intent between IO and Task -- when would I choose one over the other?

I seem to remember comments indicating that Task should generally preferred over IO, but I can't remember where I saw that now.  AFAICT both are trampolined, but Task is asynchronous, leaving perhaps not much reason to choose IO other than sidestepping the concurrency machinery.

Cheers,
Ken

Robert Norris

unread,
Jan 10, 2015, 2:34:04 AM1/10/15
to sca...@googlegroups.com

Hi Ken,

From where I sit the trend seems to be to use Task for IO, and if you simply swap IO.apply with Task.delay and .unsafePerformIO with .run your program should do the same thing; and now you have the ability to add async and all that. However there's a bunch of nice stuff you get with IO that doesn't exist (yet) for Task:

  • IO has useful exception-handling combinators
  • IO has basic console primitives (putStrLn, etc.)
  • You have MonadIO and MonadCatchIO, for lifting IO values when working with transformers
  • The mutable cell stuff (IORef, Atomic, Chan, MVar) all work in terms of IO
  • There's some resource safety stuff (Resource, which is very basic, and RegionT, which I have never figured out)

There was talk replacing all of this (Future, Task, IO) with a new implementation a while back, and it seems like people have been waiting on that rather than trying to beef up or rework it in-place. I would be interested if anyone has a status update on this.

rob 


--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.

Tony Morris

unread,
Jan 10, 2015, 4:42:53 AM1/10/15
to sca...@googlegroups.com

Is it really true that you can substitute one for the other without a significant difference in program semantics? I must be missing something.

Paul Chiusano

unread,
Jan 10, 2015, 9:40:59 AM1/10/15
to sca...@googlegroups.com

Yes that is true. If anyone can construct an example where that is not the case I would be very interested to see it.

If you formulate Task and IO as free monads, Task just adds an async instruction. If you don't use it then the behavior is the same. Task and IO in scalaz have a bunch of IMO confusing and irrelevant differences and details. (Like that IO is formulated as an ST monad instead of a free monad)

I'd still like to see a better type that unifies Task and IO and fixes all the stuff that is dumb about Task. Runar was working on this at one point and I think some other folks have as well.

Paul

Alois Cochard

unread,
Jan 10, 2015, 4:03:46 PM1/10/15
to sca...@googlegroups.com
Hi folks,

I have experimented with an alternative IO RTS system here:


Which seems to solve the problem nicely to me, but I'm not confident enough to be sure it's really a good idea ;-}

Cheers

Ken Scambler

unread,
Jan 12, 2015, 12:47:57 AM1/12/15
to sca...@googlegroups.com
Not to fill up the list with happy-talk, but thanks everyone -- the responses were both useful and interesting. Cheers.
Reply all
Reply to author
Forward
0 new messages