Skip to content

Instantly share code, notes, and snippets.

@YoEight
Last active December 31, 2015 22:09
Show Gist options
  • Select an option

  • Save YoEight/8051960 to your computer and use it in GitHub Desktop.

Select an option

Save YoEight/8051960 to your computer and use it in GitHub Desktop.
scalaz.Process and Free equiv. using simple structure encoding
sealed trait Free[F[_], A]
case class Return[F[_], A](v: A) extends Free[F, A]
case class Suspend[F[_], A](s: F[Free[F, A]]) extends Free[F, A]
sealed trait ProcessB[T[_], O, B]
case class Emit[T[_], O, B](o: O, next: B) extends ProcessB[T, O, B]
case class Await[T[_], A, O, B](ta: T[A], k: A => B) extends ProcessB[T, O, B]
case class Stop[T[_], O, B] extends ProcessB[T, O, B]
type Process[T[_], O] = Free[({ type F[x] = ProcessB[T,O,x] })#F, O]
@YoEight
Copy link
Author

YoEight commented Dec 20, 2013

Anyway, this makes me rethink about the Iteratee being just a function and the Process being interpreted...
Don't you think an iteratee as a Free becomes interpreted in some way?

Yes, but I see no benefit.

The more I look at Process vs Iteratee, the more I believe one important difference is that Process awaits the result of T[_] whereas the Iteratee uses T[_] to generate next step

That's the key. Process abstracts the way you get an 'A', allowing a lot of reuse (ex: Process1, Tye, Wye). Process also lets its driver (i.e interpreter) decides how it want to deal the result. ex:

  • I want to execute that process sequentially
  • I want to execute that process in parallel
  • I want to do crazy stuff !

@mandubian
Copy link

Ok I agree with you!
But what can't you do with iteratee from these 3 points? (trying to find the bad arguments :))
you don't really control the source in iteratee, but you can control the output!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment