-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
We now order block arguments to first type check those that do not subtract effects. This hopefully gives enough info about type arguments to uniquely determine effects of other block arguments.
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 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,3 @@ | ||
2 | ||
3 | ||
4 |
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,21 @@ | ||
interface Iter[T] { | ||
def yield(value: T): Unit | ||
} | ||
|
||
def iter[T](self: List[T]): Unit / {Iter[T]} = | ||
self match { | ||
case Cons(head, tail) => do yield(head); iter(tail) | ||
case Nil() => () | ||
} | ||
|
||
def my_map[T, U] {action: () => Unit / {Iter[T]}} {f: T => U}: Unit / {Iter[U]} = | ||
try action() | ||
with Iter[T] { | ||
def yield(value) = { do yield(f(value)); resume(()) } | ||
} | ||
|
||
def main() = | ||
try my_map { iter([1, 2, 3]) } { x => x+1 } | ||
with Iter[Int] { | ||
def yield(x) = { println(x); resume(()) } | ||
} |