region-based memory management in a c-like form
at main 853 B view raw
1T :: { field1: int, field2: int } 2Enum :: { .X1, .X2, .X3 } 3ADT :: { .X1(int), .X2(T), .X3(Enum) } 4 5foo :: 1 6 7pattern_matching :: (x: ADT) -> int { 8 match x { 9 .X1(y) => y + 1, 10 .X2(y) => y.field1 + y.field2, 11 .X3(y) => match y { 12 .X1 => 1, 13 .X2 => 2, 14 .X3 => 3 15 } 16 } 17} 18 19bar :: () : (fn(int) : int) @ R 20 with R: region 21{ 22 // colon delineates a type annotation 23 // type annotations are optional for locals 24 x : int = 1 25 26 // variables may be reassigned 27 x = 2 28 29 closure := fn(x: int) = x + 5 @ R 30 // this is a heap allocated array of 5 ints 31 array := [4]{1, 2, 3, 4} @ R 32 // this is stack allocated, because it is not given a region to allocate in 33 stack_array := [2]{1, 2} 34 // this is a slice, which is dynamically sized 35 slice_array := [][1, 2, 3] @ R 36 37 return closure 38}