Skip to content

Wyn v1.14: The Polish Release

v1.13 made Wyn feel like Python. v1.14 sands down the last rough edges — the ones you hit while writing real code, not while reading the tour.

The headline is the type system finally showing its clean face. Optionals and results have been in the language for a long time, but until now their return types leaked the compiler's internal, mangled names. That's fixed. Everything here is backward compatible — no source changes are required to upgrade.

Clean optional and result return types

You could always write int? and Result<int, string> for variables. Now they work as return types too, so a signature reads the way you'd say it out loud:

wyn
fn find(t: int) -> int? {
    if t > 0 { return Some(t) }
    return None()
}

fn parse(s: string) -> Result<int, string> {
    if s == "" { return Err("empty") }
    return Ok(42)
}

No more -> OptionInt or -> ResultInt. The constructors in the body still lower to the right underlying type; you just don't have to spell it.

match, as an expression

match on an Option or Result now yields a value, for any payload type. So the common "collapse both arms into one string" pattern is a single binding:

wyn
fn parse(s: string) -> Result<int, string> {
    if s == "" { return Err("empty") }
    return Ok(42)
}

var r = parse("42")
var msg = match r {
    Ok(v) => v.to_string(),
    Err(e) => e,
}
println(msg)                       // 42

Options are the same:

wyn
var opt: string? = Some("Wyn")
var name = match opt {
    Some(v) => v,
    None => "anonymous",
}
println(name)                      // Wyn

Default arguments infer their type

If a parameter has a default, its type is inferred from that default — the annotation becomes optional:

wyn
fn greet(who = "world") -> string {
    return "Hello, ${who}!"
}

fn dial(host = "localhost", port = 8080) {
    println("Connecting to ${host}:${port}")
}

greet()              // Hello, world!
dial("0.0.0.0")      // Connecting to 0.0.0.0:8080

Typed defaults still work — this is purely a "you can write less" change.

The little things

Three small fixes that each remove a papercut:

wyn
// println prints an array's real values
println([1, 2, 3])                 // [1, 2, 3]

// negative string indexing, like arrays
var s = "hello"
println(s[-1])                     // o

// if/else where every branch returns: no trailing return needed
fn classify(n: int) -> string {
    if n > 0 {
        return "positive"
    } else {
        return "non-positive"
    }
}

Upgrading

bash
wyn --version        # 1.14.0

No source changes are required. v1.14.0 is a drop-in upgrade over v1.13.0 — and if you have any mangled -> OptionInt / -> ResultInt return types lying around, this is a good time to swap them for the clean int? / Result<int, string> forms.


Read the full what's new in v1.14, or browse the version history.

MIT License — v1.14