flan/test/syntax/infer/main.fln

43 lines
882 B
Plaintext

;; Return types read off the body: no arrow here, _ in the return slot in
;; main.flan. Each shape the rule has: one type, a call's type, a literal
;; that takes the other exit's type, a dyn beside a literal, nothing (()), a return
;; that never falls off the end, and a function that calls itself and gives
;; nothing.
fn add(x: i32, y: i32) = x + y
fn half(x: f64) = x / 2.0
fn quarter(x: f64) = half(half(x))
fn pick(c: bool)
if c
return 1
2.5
fn label(c: bool, d)
if c
return d
0
fn say(x: i32) = println(x)
fn- floor0(x: i32)
if x < 0 then return 0 else x
fn countdown(n: i32)
if n > 0
println(n)
countdown(n - 1)
fn main() -> i32
println(add(1, 2))
println(quarter(10.0))
println(pick(true) + 0.5)
println(pick(false))
println(label(true, "yes"), label(false, "yes"))
say(4)
println(floor0(-3), floor0(5))
countdown(2)
0