// 실행되는 첫 프로그램. // // main은 자기가 선언한 capability만 받는다. Console을 파라미터에서 지우면 // print할 방법이 프로그램 안에 없다 — ambient authority가 없다는 것의 // 실행 시점 의미다. // // 표준 라이브러리도 명시적으로 가져온다. prelude가 없다 — // 암묵적으로 끌어오지 않는다는 규칙에 예외를 두지 않는다. // // 기대 출력: // area = 12 // area = 9 // area = 3 import "cool.dev/std/list" as List import "cool.dev/std/string" as String import "cool.dev/std/int" as Int pub capability Console { fn print(s: String) effects {Console.print} } pub enum Shape { Circle(Int), Square(Int), } pub fn area(s: Shape) -> Int { match s { Circle(r) => r * r * 3, Square(w) => w * w, } } pub fn main(c: Console) effects {Console.print} { let shapes = [Circle(2), Square(3), Circle(1)] List.each(shapes, fn(s) { c.print(String.concat("area = ", Int.show(area(s)))) }) }