Skip to main content

CSHARP_RUNTIME

Constant CSHARP_RUNTIME 

Source
pub const CSHARP_RUNTIME: &str = r#"
/// <summary>OxiLean C# Runtime helpers.</summary>
internal static class OxiLeanRt
{
    /// <summary>Called when pattern matching reaches an unreachable branch.</summary>
    public static T Unreachable<T>() =>
        throw new InvalidOperationException("OxiLean: unreachable code reached");

    /// <summary>Natural number addition (long arithmetic).</summary>
    public static long NatAdd(long a, long b) => a + b;

    /// <summary>Natural number subtraction (saturating at 0).</summary>
    public static long NatSub(long a, long b) => Math.Max(0L, a - b);

    /// <summary>Natural number multiplication.</summary>
    public static long NatMul(long a, long b) => a * b;

    /// <summary>Natural number division (truncating, 0 if divisor is 0).</summary>
    public static long NatDiv(long a, long b) => b == 0L ? 0L : a / b;

    /// <summary>Natural number modulo.</summary>
    public static long NatMod(long a, long b) => b == 0L ? a : a % b;

    /// <summary>Boolean to nat (decidable equality).</summary>
    public static long Decide(bool b) => b ? 1L : 0L;

    /// <summary>String representation of a natural number.</summary>
    public static string NatToString(long n) => n.ToString();

    /// <summary>String append.</summary>
    public static string StrAppend(string a, string b) => a + b;

    /// <summary>List.cons — prepend element to list.</summary>
    public static List<A> Cons<A>(A head, List<A> tail)
    {
        var result = new List<A> { head };
        result.AddRange(tail);
        return result;
    }

    /// <summary>List.nil — empty list.</summary>
    public static List<A> Nil<A>() => new List<A>();

    /// <summary>Option.some.</summary>
    public static A? Some<A>(A value) where A : class => value;

    /// <summary>Option.none.</summary>
    public static A? None<A>() where A : class => null;
}
"#;
Expand description

Minimal C# runtime helper class emitted at the end of every generated file.