Conditional branching
-- Booleans are built in, and `if` only evaluates the branch it picks.
describe : Number -> String = \n.
(if (lt n 0) "negative"
(if (eq n 0) "zero" "positive"))
(println (describe -5))
(println (describe 0))
(println (describe 7))
-- Booleans can also be built from lambdas alone (Church encoding).
churchTrue : a -> a -> a = \x. \y. x
churchFalse : a -> a -> a = \x. \y. y
churchToString : (String -> String -> String) -> String = \bool. (bool "true" "false")
(println (churchToString churchTrue))
(println (churchToString churchFalse))
Output
negative
zero
positive
true
false
Run it yourself from the repository root: lbd run examples/conditional_branching.lbd