HoldFastPlayground
Browser

HoldFast Playground

HoldFast is a systems programming language with ownership, borrowing, and mathematical proofs. Edit an example, then select Run in the Console to evaluate an expression. Select Compile to see Gallina for the default example. See what each mode checks.

Load an example
playground.hf
Start with Square(7) in the Console. Change 7 to try another natural number.
Compile-time evaluation

Evaluate an expression using the current source. Choose Nat for a natural number or bool for true or false.

Select Run or choose a suggestion to evaluate an expression.

Ready to explore
Connecting…

Runnable examples

Load an example, then choose a suggested expression in the Console to run it.

Indexed vectors and proofs

A vector’s length is part of its type. A Fin<n> index selects one of its n positions.

public definition Vec<TElement, length> Copy<TElement, ghost Nat length>(
    Vec<TElement, length> values) => values;

public lemma SameValue() ensures PreservedValue() == 42
    proof { assert PreservedValue() == 42; }
Elaborator spec

Raw strings and checked formatting

A multiline raw string dedents against its closing delimiter. If an append exceeds capacity, Write preserves the existing bytes and returns a builder with Fits == false.

public TextBuilder<36> FormatPacket(Nat id, bool ok) {
    let TextBuilder<36> builder = TextBuilder.Empty();
    let TextBuilder<36> hdr = builder.Write($"hdr={HeaderTag()} ");
    return hdr.Write($"id=0x{id:x4} ok={ok}");
}
Surface grammar

Records and properties

Read a computed property or construct an updated record with with { … }.

public record Counter(Nat Value, Nat Limit) {
    public bool AtLimit => this.Value >= this.Limit;
}
public definition Counter Advance(Counter counter, Nat step) =>
    if (counter.AtLimit) counter else counter with { Value = counter.Value + step };
Reference

Compile-time constants

A const parameter supplies a compile-time value. A regular parameter can carry runtime data.

public Nat Scale(const Nat gain, Nat sample) {
    const Nat multiplier = Square(gain);
    return multiplier * sample;
}
Constant syntax

Systems language tour

These examples illustrate the systems features in dependent.hf. See the first-release contract for qualification requirements.

Argument modes

Example

Mark loan arguments with in, ref, or out, and ownership transfers with move. A method declaration supplies its receiver’s mode. Loan rules

public u32 SumInitializedBounds()
{
    InitBounds(10, out var low, out var high);
    return low + high;
}

Selective invariant lifting

Example

Ordered requires Low <= High. Setting Low to 4 temporarily breaks it because High is 3. Setting High to 9 restores it before the block closes. Contract rules

public RangeWindow RebalanceWindow()
{
    var window = RangeWindow(2, 3);
    open (ref window) lifts Ordered
    {
        window.Low = 4;
        window.High = 9;
    }
    return window;
}

Bounded loops

Example

A half-open low..high range bounds a foreach loop. A while loop states its invariant and decreasing measure. Loop rules

public usize CountUpTo(usize limit)
    requires limit <= 8usize
    ensures result == limit
{
    var i = 0usize;
    while (i < limit)
        invariant i <= limit
        decreases limit - i
    {
        i += 1usize;
    }
    return i;
}

What the playground checks

Browser
Compile generates Gallina for the pure Nat and bool subset. For broader examples, Run evaluates a sample expression and Compile shows a preview. Open Problems to see unchecked proof obligations.
Local compiler
Compile checks one module and emits Gallina for supported loans, natural usage grades, contracts and dependent types. Launch the local compiler
Rocq replay
Use Rocq to check the emitted proof terms. The repository qualification command also audits the assumptions of its examples. Replay a Playground proof

Documentation

Full documentation index