// 실행 의미를 한 파일에 모은 것: ?, mut, struct, match, scope. // // 기대 출력: // 7 // 6 // err // in scope import "cool.dev/std/int" as Int pub capability Console { fn print(s: String) effects {Console.print} } pub enum E { Bad, } pub copyable struct P { x: Int, y: Int, } pub fn half(n: Int) -> Result[Int, E] { if n % 2 == 0 { Ok(n / 2) } else { Err(Bad) } } pub fn twice(n: Int) -> Result[Int, E] { let a = half(n)? let b = half(a)? Ok(a + b) } pub fn show_res(r: Result[Int, E]) -> String { match r { Ok(v) => Int.show(v), Err(_) => "err", } } pub fn main(c: Console, root: TaskScope) effects {Console.print} { let mut total = 0 let p = P { x: 3, y: 4 } total = total + p.x + p.y c.print(Int.show(total)) c.print(show_res(twice(8))) c.print(show_res(twice(7))) scope sc = root { sc.spawn(fn() { c.print("in scope") }) } }