sifr run, type-checking it with sifr check, and compiling it to a standalone native binary with sifr build. The example uses union types and Result-based error handling — two of Sifr’s most important features — so you leave with a clear picture of how the language works in practice.
Create your Sifr file
Create a new file called A few things to notice before you run this:
greet.sifr. This program looks up a user’s age from a dictionary (demonstrating safe indexing with int | None), parses a string into an integer (demonstrating Result and compile-enforced error handling), and narrows a union type with isinstance.greet.sifr
users["charlie"]returnsint | None. The compiler prevents you from usingageas a plainintuntil you check theNonebranch.parse_agedeclaresResult[int, ParseError]. If you remove theexcept ParseErrorblock inmain, the compiler rejects the program.isinstance(val, int)narrows the type ofvalinside each branch automatically — no cast required.
Type-check without compiling
Before running the program, use If everything is correct, the command exits silently with a zero status code. If you have a type error — for example, you forgot to handle the
sifr check to catch any type errors. This is the fastest feedback loop during development because it skips code generation entirely.ParseError branch — sifr check tells you exactly which line and why.Run the program
Use Expected output:
sifr run to compile and execute greet.sifr in a single command. You do not need to manage intermediate build artifacts.user not found appears because "charlie" is not in the users dictionary and the missing-key path returns None. parsed age: 25 confirms that parse_age("25") returned Ok(25) and the compiler unwrapped it automatically at the try site.Build a native binary
When you are ready to ship, use Run the resulting binary directly:The output is identical to
sifr build to compile greet.sifr into a standalone native binary. No runtime or interpreter is bundled — the output is a plain executable linked against the system.sifr run, but the binary is self-contained and can be distributed to any compatible platform without installing Sifr.Inspect the generated Rust
Curious what Sifr emits under the hood? Use The output is valid Rust source that you can read, audit, or paste into the Rust playground for further experimentation.
sifr emit to print the generated Rust source without producing a binary. This is useful for understanding the ownership model and verifying that the compiler is doing what you expect.What you just did
You wrote a Sifr program that exercises three core language features:- Safe indexing — dictionary access returns
int | None, eliminating key-not-found crashes at the type level. - Result-based error handling —
parse_agereturnsResult[int, ParseError], and the compiler enforces that every call site handles the error branch. - Automatic type narrowing —
isinstancechecks insideif/elsenarrow the union type in each branch without explicit casts.