{ "schema": "ailang/v0", "name": "eq_ord_user_adt", "imports": [], "defs": [ { "kind": "type", "name": "IntBox", "vars": [], "doc": "A one-field box around an Int, used to demonstrate that the unified mono pass synthesises eq__IntBox from a user-written instance, not from the primitive == operator.", "ctors": [ { "name": "MkIntBox", "fields": [{ "k": "con", "name": "Int" }] } ] }, { "kind": "instance", "class": "Eq", "type": { "k": "con", "name": "IntBox" }, "doc": "Eq IntBox by structural unwrap of the inner Int.", "methods": [ { "name": "eq", "body": { "t": "lam", "params": ["a", "b"], "paramTypes": [ { "k": "con", "name": "IntBox" }, { "k": "con", "name": "IntBox" } ], "retType": { "k": "con", "name": "Bool" }, "body": { "t": "match", "scrutinee": { "t": "var", "name": "a" }, "arms": [{ "pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "ai" }] }, "body": { "t": "match", "scrutinee": { "t": "var", "name": "b" }, "arms": [{ "pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "bi" }] }, "body": { "t": "app", "fn": { "t": "var", "name": "==" }, "args": [ { "t": "var", "name": "ai" }, { "t": "var", "name": "bi" } ] } }] } }] } } } ] }, { "kind": "instance", "class": "Ord", "type": { "k": "con", "name": "IntBox" }, "doc": "Ord IntBox by delegating to Int's compare on the inner field.", "methods": [ { "name": "compare", "body": { "t": "lam", "params": ["a", "b"], "paramTypes": [ { "k": "con", "name": "IntBox" }, { "k": "con", "name": "IntBox" } ], "retType": { "k": "con", "name": "prelude.Ordering" }, "body": { "t": "match", "scrutinee": { "t": "var", "name": "a" }, "arms": [{ "pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "ai" }] }, "body": { "t": "match", "scrutinee": { "t": "var", "name": "b" }, "arms": [{ "pat": { "p": "ctor", "ctor": "MkIntBox", "fields": [{ "p": "var", "name": "bi" }] }, "body": { "t": "app", "fn": { "t": "var", "name": "compare" }, "args": [ { "t": "var", "name": "ai" }, { "t": "var", "name": "bi" } ] } }] } }] } } } ] }, { "kind": "fn", "name": "main", "type": { "k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" }, "effects": ["IO"] }, "params": [], "body": { "t": "seq", "lhs": { "t": "do", "op": "io/print_int", "args": [{ "t": "if", "cond": { "t": "app", "fn": { "t": "var", "name": "eq" }, "args": [ { "t": "ctor", "type": "IntBox", "ctor": "MkIntBox", "args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }] }, { "t": "ctor", "type": "IntBox", "ctor": "MkIntBox", "args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }] } ] }, "then": { "t": "lit", "lit": { "kind": "int", "value": 1 } }, "else": { "t": "lit", "lit": { "kind": "int", "value": 0 } } }] }, "rhs": { "t": "do", "op": "io/print_int", "args": [{ "t": "if", "cond": { "t": "app", "fn": { "t": "var", "name": "eq" }, "args": [ { "t": "ctor", "type": "IntBox", "ctor": "MkIntBox", "args": [{ "t": "lit", "lit": { "kind": "int", "value": 3 } }] }, { "t": "ctor", "type": "IntBox", "ctor": "MkIntBox", "args": [{ "t": "lit", "lit": { "kind": "int", "value": 5 } }] } ] }, "then": { "t": "lit", "lit": { "kind": "int", "value": 1 } }, "else": { "t": "lit", "lit": { "kind": "int", "value": 0 } } }] } } } ] }