{ "schema": "ailang/v0", "name": "data_with_match", "imports": [], "defs": [ { "kind": "type", "name": "List", "doc": "Monomorphic singly-linked Int list \u2014 boxed, recursive.", "ctors": [ { "name": "Nil", "fields": [] }, { "name": "Cons", "fields": [ { "k": "con", "name": "Int" }, { "k": "con", "name": "List" } ] } ] }, { "kind": "fn", "name": "head_or_zero", "doc": "Return the head of xs, or 0 if empty. Exercises TermMatch with two arms, PatternCtor (both nullary Nil and binary Cons), and PatternWild on the tail field.", "type": { "k": "fn", "params": [ { "k": "con", "name": "List" } ], "param_modes": [ "borrow" ], "ret": { "k": "con", "name": "Int" }, "ret_mode": "own", "effects": [] }, "params": [ "xs" ], "body": { "t": "match", "scrutinee": { "t": "var", "name": "xs" }, "arms": [ { "pat": { "p": "ctor", "ctor": "Nil", "fields": [] }, "body": { "t": "lit", "lit": { "kind": "int", "value": 0 } } }, { "pat": { "p": "ctor", "ctor": "Cons", "fields": [ { "p": "var", "name": "h" }, { "p": "wild" } ] }, "body": { "t": "var", "name": "h" } } ] } }, { "kind": "fn", "name": "count_via_letrec", "doc": "Walk xs counting nodes using a local recursive let. Exercises TermLetRec and TermVar; the recursive `go` is bound locally.", "type": { "k": "fn", "params": [ { "k": "con", "name": "List" } ], "param_modes": [ "own" ], "ret": { "k": "con", "name": "Int" }, "ret_mode": "own", "effects": [] }, "params": [ "xs" ], "body": { "t": "letrec", "name": "go", "type": { "k": "fn", "params": [ { "k": "con", "name": "List" } ], "param_modes": [ "own" ], "ret": { "k": "con", "name": "Int" }, "ret_mode": "own", "effects": [] }, "params": [ "ys" ], "body": { "t": "match", "scrutinee": { "t": "var", "name": "ys" }, "arms": [ { "pat": { "p": "ctor", "ctor": "Nil", "fields": [] }, "body": { "t": "lit", "lit": { "kind": "int", "value": 0 } } }, { "pat": { "p": "ctor", "ctor": "Cons", "fields": [ { "p": "wild" }, { "p": "var", "name": "t" } ] }, "body": { "t": "app", "fn": { "t": "var", "name": "+" }, "args": [ { "t": "lit", "lit": { "kind": "int", "value": 1 } }, { "t": "app", "fn": { "t": "var", "name": "go" }, "args": [ { "t": "var", "name": "t" } ] } ] } } ] }, "in": { "t": "app", "fn": { "t": "var", "name": "go" }, "args": [ { "t": "var", "name": "xs" } ] } } } ] }