tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

binding_support.tri (717B)


      1 -- Compiler-owned helpers and exact-identity contracts for stable binding elimination.
      2 -- choose: saturated three-argument selector; not: canonical Boolean negation.
      3 -- Neither contract is inferred from a user-supplied source name.
      4 !import native_math as N
      5 !export *
      6 triage leaf stem fork = t (t leaf stem) fork
      7 choose yes no value = triage no (_ : yes) (_ _ : yes) value
      8 lazy yes no value = choose yes no value t
      9 head value = triage t (_ : t) (a _ : a) value
     10 tail value = triage t (_ : t) (_ b : b) value
     11 both a b = choose b t a
     12 either a b = choose (t t) b a
     13 not value = choose t (t t) value
     14 map f xs = triage t (_ : t) (a b : t (f a) (map f b)) xs
     15 width xs = triage 0 (_ : 0) (_ rest : N.successor (width rest)) xs