Skip to content

Instantly share code, notes, and snippets.

@gseitz
Created April 29, 2012 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gseitz/2552623 to your computer and use it in GitHub Desktop.
Save gseitz/2552623 to your computer and use it in GitHub Desktop.
trying to unbork ApplicativePlus.{some, many}
// original, broken version
def many[A](a: F[A]): F[List[A]] = {
lazy val y: Free.Trampoline[F[List[A]]] = z map (plus(_, point(Nil)))
lazy val z: Free.Trampoline[F[List[A]]] = y map (map2(a, _)(_ :: _))
y.run
}
// trying to make sense of trampoline
def many[A](a: F[A]): F[List[A]] = {
import std.function._
lazy val y: Free.Trampoline[F[List[A]]] = Free.return_[Function0, F[List[A]]](plus(z.run, point(Nil)))
lazy val z: Free.Trampoline[F[List[A]]] = Free.return_[Function0, F[List[A]]](map2(a, y.run)(_ :: _))
y.run
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment