Created
April 29, 2012 18:51
-
-
Save gseitz/2552623 to your computer and use it in GitHub Desktop.
trying to unbork ApplicativePlus.{some, many}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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