; 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/0005-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 (own (con Str))) (ret (own (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 (own (con Unit))) (effects IO)))
    (params)
    (body
      (seq (seq (app print (app eq 5 5)) (do io/print_str "\n"))
      (seq (seq (app print (app eq 5 6)) (do io/print_str "\n"))
      (seq (seq (app print (app eq true false)) (do io/print_str "\n"))
      (seq (seq (app print (app eq true true)) (do io/print_str "\n"))
      (seq (seq (app print (app eq "hi" "hi")) (do io/print_str "\n"))
      (seq (seq (app print (app eq "hi" "ho")) (do io/print_str "\n"))
      (seq (seq (app print (app eq (lit-unit) (lit-unit))) (do io/print_str "\n"))
      (seq (seq (app print (app classify_str "hi")) (do io/print_str "\n"))
      (seq (seq (app print (app classify_str "ho")) (do io/print_str "\n"))
           (seq (app print (app classify_str "??")) (do io/print_str "\n"))))))))))))))
