Hello World
Create a file called hello.ki:
// hello.ki - Your first Kira program
effect fn main() -> void {
std.io.println("Hello, Kira!")
}Run it:
kira run hello.kiOutput:
Hello, Kira!Breaking It Down
effect fn main()declares an effect function namedmain-> voidmeans it returns nothingstd.io.printlnis a standard library function for printing- The
effectkeyword indicates this function performs side effects (I/O)
A More Interesting Example
Here's a program that demonstrates several Kira features:
type Shape =
| Circle(f64)
| Rectangle(f64, f64)
fn area(shape: Shape) -> f64 {
var result: f64 = 0.0
match shape {
Circle(r) => { result = 3.14159 * r * r }
Rectangle(w, h) => { result = w * h }
}
return result
}
effect fn main() -> void {
let circle: Shape = Circle(5.0)
let rect: Shape = Rectangle(3.0, 4.0)
std.io.println("Circle area: " + to_string(area(circle)))
std.io.println("Rectangle area: " + to_string(area(rect)))
}This demonstrates:
- Sum types (
Shapewith variantsCircleandRectangle) - Pattern matching to handle each variant
- Pure functions (
areahas no side effects) - Effect functions (
mainperforms I/O) - Explicit types on every binding
Next Steps
- Learn about basic types
- Understand the effects system
- Explore the CLI options