C++ can #include a .k file. Kairo can call any C++ library
with zero bindings. The boundary doesn't exist.
stage(0) written in C++ · stage(1) self-hosting in progress
import std::Parallel
import std::Error::DimensionError
import std::Interfaces::Numeric
fn <T impl Numeric> dot(a: [T], b: [T]) -> T {
if a.length() != b.length() {
panic DimensionError("dot requires equal lengths")
}
var result = Parallel::reduce(
policy: Parallel::Policy::SIMD,
range: 0..(a.length()),
init: 0 as T,
step: fn (i: usize) -> T = a[i] * b[i],
combine: fn (x: T, y: T) -> T = x + y
)
return result ?? 0
}
test "dot product of two vectors" {
var a, b = [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]
var result = dot(a, b)
assert result == 130, f"excepted 130, got {result}"
} import std // import only what you need, nothing more
// No main() required top-level code runs immediately
// or is callable when imported as a module.
const name = "Kairo"
var count = 0
for i in 0..5 {
std::print(f"Hello, {name}! Count is {count}.")
count++
}
std::print(f"Ran {count} times.") Readable from day one
var count = 0 the compiler knows it's an integer. Annotate when you want to, not because you have to. f"" strings let you embed expressions directly. No concatenation, no format specifiers. main() boilerplate. Code at the top level runs on execution and can still be imported as a module. One command gets you the compiler, formatter, LSP, and package manager. No separate installs, no configuration.
Compiler, standard library, and toolchain are on GitHub. Apache 2.0 with runtime exception.