NewsCrawler.org

Syl: Dependent Types at Compile Time via a Modal Type System

Syl is a programming language that encodes compile-time computation in a modal type system[1], drawing on András Kovács' work on two-level type theory and on plans for OxCaml. The motivation is that existing compile-time features — templates and constexpr in C++, const generics in Rust, comptime in Zig, _Generic in C — tend to be highly restricted, lack a proper type system, or both.

Modes describe properties of values independent of their types — OxCaml uses them for properties like unique ownership, writability, or permission to send a value to another thread — and in Syl every value carries a mode on two axes: staticity, where a static value is knowable at compile time and a dynamic one may not be, and erasure, where an unerased value is knowable at runtime and an erased one may not be. Modes can be weakened but not strengthened: a static value may be treated as dynamic and an unerased value as erased, but not the reverse. Functions with static parameters undergo monomorphization[2]: calling such a function selects an implementation specialized to the argument's value, so f true compiles to a call that hard-codes print_bool true. The if erased construct accepts a static erased condition and is guaranteed to resolve at compile time, which yields dependent types[3]: a function can return an int when its argument is true and a bool otherwise, with the type erased bool as x -> if erased x then int else bool.

There is no distinct type grammar: int and bool are just erased values of type type, and abstracting over them gives polymorphism; Syl is thus dependently typed at compile time and simply typed at runtime, since types are always erased and the runtime program cannot inspect them. Because Syl supports general recursion in compile-time computations and allows type : type, constructing an expression of a given type does not prove the corresponding proposition, unlike in Lean, Rocq, or Agda. As a result, typechecking is not decidable, and the compiler must evaluate all applications that produce proofs before relying on their results. In return, Syl needs no totality checker[4] or universe machinery, guards against runaway compile-time recursion with fuel limits, and supports partial functions through an unreachable keyword that asserts a branch does not appear in the runtime program.

Read the original thenumb.atDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page