; Equality dispatch via the prelude.Eq class for Int/Bool/Str/Unit. ; Each `(app eq x y)` call resolves to the matching primitive Eq ; instance, lowered via try_emit_primitive_instance_body in the ; codegen: ; Int → icmp eq i64 ; Bool → icmp eq i1 ; Str → @ail_str_eq (strcmp-based) ; Unit → constant i1 true (single-inhabitant type) ; ; Float has no Eq instance; partial-Float comparison is done via ; the explicit float_eq / float_lt / etc. fns (see ; design/contracts/float-semantics.md). ; ; This fixture exercises all four supported types, both directly via ; `(app eq ...)` and indirectly via the lit-pattern desugar (which ; rewrites `(pat-lit "hi")` → `(if (eq sv "hi") body fall_k)` and ; therefore inherits the same class-dispatch path). ; ; Expected stdout (one per line): ; true ; (eq 5 5) ; false ; (eq 5 6) ; false ; (eq true false) ; true ; (eq true true) ; true ; (eq "hi" "hi") ; false ; (eq "hi" "ho") ; true ; (eq () ()) ; 1 ; classify_str "hi" (lit-pattern hits 1 arm) ; 2 ; classify_str "ho" (lit-pattern hits 2 arm) ; 0 ; classify_str "??" (default arm) ; ; Driver routes through the polymorphic `print` helper (Show Bool / Show Int). (module eq_demo (fn classify_str (doc "Lit-pattern over Str; exercises build_eq's class-dispatch lowering for non-Int.") (type (fn-type (params (con Str)) (ret (con Int)))) (params s) (body (match s (case (pat-lit "hi") 1) (case (pat-lit "ho") 2) (case _ 0)))) (fn main (doc "Drive eq at Int/Bool/Str/Unit; then drive classify_str.") (type (fn-type (params) (ret (con Unit)) (effects IO))) (params) (body (seq (app print (app eq 5 5)) (seq (app print (app eq 5 6)) (seq (app print (app eq true false)) (seq (app print (app eq true true)) (seq (app print (app eq "hi" "hi")) (seq (app print (app eq "hi" "ho")) (seq (app print (app eq (lit-unit) (lit-unit))) (seq (app print (app classify_str "hi")) (seq (app print (app classify_str "ho")) (app print (app classify_str "??"))))))))))))))