;;;; A generic conversion from an enum, licensed by {:where (is-enum $t)}. is-enum ;;;; admits exactly the enums and entails is-ordered and is-equal, so a body under ;;;; it may convert, compare and test for equality, at any enum. (defenum Color [red green blue]) (defenum Size [small 10 large 20]) (defn code [x $t] i32 {:where (is-enum $t)} (i32 x)) (defn is-later [a $t b $t] bool {:where (is-enum $t)} (> a b)) (defn is-same [a $t b $t] bool {:where (is-enum $t)} (and (= a b) (<= a b))) (defn main [] i32 (let [c (Color 2) s (Size 20)] (println (code c)) ; 2 (println (code s)) ; 20 (println (is-later c (Color 0))) ; true (println (is-same (Color 1) (Color 1))) ; true (println (f64 (code s)))) ; 20 0)