aboutsummaryrefslogtreecommitdiff
path: root/examples/30-effect-handler-pop-on-return/src/HelloWorld.shed
blob: 4e91f8b440d7ed544b653b3b74fe3af91db310eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
effect Writer {
    fun hello() -> Unit;
    fun world() -> Unit;
}

pub fun main() ! Io -> Unit {
    try {
        hello!();
        Writer.world!();
        print!("\n");
        return;
    } handle Writer {
        fun hello() {
            print!("wrong hello");
            resume;
        }

        fun world() {
            print!("world");
            resume;
        }
    }
}

fun hello() ! Io -> Unit {
    try {
        Writer.hello!();
        print!(", ");
        return;
    } handle Writer {
        fun hello() {
            print!("hello");
            resume;
        }

        fun world() {
            print!("wrong world");
            resume;
        }
    }
}