flan/test/syntax/infer/main.flan

28 lines
632 B
Plaintext

;; Return types read off the body: _ in the return slot here, no arrow in
;; main.fln. Each shape the rule has: one type, a call's type, two types
;; (dyn), nothing (()), and a return that never falls off the end.
(defn add [x i32 y i32] _ (+ x y))
(defn half [x f64] _ (/ x 2.0))
(defn quarter [x f64] _ (half (half x)))
(defn pick [c bool] _
(when c (return 1))
2.5)
(defn say [x i32] _ (println x))
(defn- floor0 [x i32] _
(if (< x 0) (return 0) x))
(defn main [] i32
(println (add 1 2))
(println (quarter 10.0))
(println (pick true))
(println (pick false))
(say 4)
(println (floor0 -3) (floor0 5))
0)