(module eq_ord_user_adt (data IntBox (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.") (ctor MkIntBox (con Int))) (instance (class prelude.Eq) (type (con IntBox)) (doc "Eq IntBox by structural unwrap of the inner Int.") (method eq (body (lam (params (typed a (con IntBox)) (typed b (con IntBox))) (ret (con Bool)) (body (match a (case (pat-ctor MkIntBox ai) (match b (case (pat-ctor MkIntBox bi) (app eq ai bi)))))))))) (instance (class prelude.Ord) (type (con IntBox)) (doc "Ord IntBox by delegating to Int's compare on the inner field.") (method compare (body (lam (params (typed a (con IntBox)) (typed b (con IntBox))) (ret (con prelude.Ordering)) (body (match a (case (pat-ctor MkIntBox ai) (match b (case (pat-ctor MkIntBox bi) (app compare ai bi)))))))))) (fn main (type (fn-type (params) (ret (own (con Unit))) (effects IO))) (params) (body (seq (seq (app print (if (app eq (term-ctor IntBox MkIntBox 3) (term-ctor IntBox MkIntBox 3)) 1 0)) (do io/print_str "\n")) (seq (app print (if (app eq (term-ctor IntBox MkIntBox 3) (term-ctor IntBox MkIntBox 5)) 1 0)) (do io/print_str "\n"))))))