use "basic_models.g"; struct node where { DefaultConstructible, Regular } { node* next; T data; }; fun cons where { DefaultConstructible, Regular } (T x, node* n) -> node*@ { return new node{data = x, next = n}; } fun free_list where { DefaultConstructible, Regular } (node* n) { if (n != cast*>(nullptr)) { free_list(n->next); delete n; } } fun map where { DefaultConstructible, Regular, DefaultConstructible, Regular } ((fun(T)->U@) f, node* n) -> node*@ { if (n == cast*>(nullptr)) return nullptr; else return cons(f(n->data), map(f, n->next)); } fun add1(int x) -> int@ { return x + 1; } fun main() -> int@ { let ls1 = cons(0, cons(1, cons(2, cast*>(nullptr)))); let ls2 = map(add1, ls1); let x = (*ls2).data - 1; free_list(ls1); free_list(ls2); return x; }