-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back LazyCons, since that version also works now under the new rules
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class CC | ||
type Cap = {*} CC | ||
|
||
trait LazyList[+A]: | ||
this: ({*} LazyList[A]) => | ||
|
||
def isEmpty: Boolean | ||
def head: A | ||
def tail: {this} LazyList[A] | ||
|
||
object LazyNil extends LazyList[Nothing]: | ||
def isEmpty: Boolean = true | ||
def head = ??? | ||
def tail = ??? | ||
|
||
class LazyCons[+T](val x: T, val xs: {*} () => {*} LazyList[T]) extends LazyList[T]: | ||
this: ({*} LazyList[T]) => | ||
|
||
def isEmpty = false | ||
def head = x | ||
def tail: {this} LazyList[T] = xs() | ||
|
||
extension [A](xs: {*} LazyList[A]) | ||
def map[B](f: {*} A => B): {xs, f} LazyList[B] = | ||
if xs.isEmpty then LazyNil | ||
else LazyCons(f(xs.head), () => xs.tail.map(f)) | ||
|
||
def test(cap1: Cap, cap2: Cap) = | ||
def f(x: String): String = if cap1 == cap1 then "" else "a" | ||
def g(x: String): String = if cap2 == cap2 then "" else "a" | ||
|
||
val xs = LazyCons("", () => if f("") == f("") then LazyNil else LazyNil) | ||
val xsc: {cap1} LazyList[String] = xs | ||
val ys = xs.map(g) | ||
val ysc: {cap1, cap2} LazyList[String] = ys |