-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Is there a way to implement a handler similar to ambList that returns a stream, lazily returning the results?
My naive attempt did not work, but will result in an infinite loop:
def ambStream[R](prog: Amb => Control[R]): Control[Stream[R]] =
new Handler[Stream[R]] with Amb {
def flip() = use { resume =>
for {
x <- resume(true)
y <- resume(false)
} yield x ++ y
}
} handle { amb => prog(amb).map(Stream(_)) }
def flip(implicit amb: Amb): Control[Boolean] = amb.flip()
def from(n: Int)(implicit amb: Amb): Control[Int] = for {
x <- flip
y <- if (x) pure(n) else from(n + 1)
} yield yMetadata
Metadata
Assignees
Labels
No labels