Skip to content

Coming from Go

Side-by-side comparisons for Go developers.

Variables

go
// Go
name := "Alice"
var age int = 30
const PI = 3.14
wyn
// Wyn
var name = "Alice"
var age: int = 30
const PI = 3.14

Functions

go
// Go
func add(a, b int) int {
    return a + b
}
wyn
// Wyn
fn add(a: int, b: int) -> int {
    return a + b
}

Error Handling

go
// Go
result, err := doSomething()
if err != nil {
    return err
}
wyn
// Wyn
var result = doSomething()
match result {
    Ok(v) => println("${v}")
    Err(e) => println("error: " + e)
}

Goroutines vs Spawn

go
// Go
go func() {
    result := heavyWork()
    ch <- result
}()
val := <-ch
wyn
// Wyn
var future = spawn heavyWork()
var val = await future

Channels

go
// Go
ch := make(chan int, 10)
ch <- 42
val := <-ch
wyn
// Wyn
var ch = Task.channel(10)
Task.send(ch, 42)
var val = Task.recv(ch)

Structs & Methods

go
// Go
type Point struct {
    X, Y int
}

func (p Point) Distance(other Point) float64 {
    dx := float64(other.X - p.X)
    dy := float64(other.Y - p.Y)
    return math.Sqrt(dx*dx + dy*dy)
}
wyn
// Wyn
struct Point {
    x: int
    y: int

    fn distance(self, other: Point) -> float {
        var dx = (other.x - self.x) * (other.x - self.x)
        var dy = (other.y - self.y) * (other.y - self.y)
        return Math.sqrt(dx + dy)
    }
}

Pattern Matching (vs switch)

go
// Go
switch n {
case 0:
    fmt.Println("zero")
case 1:
    fmt.Println("one")
default:
    fmt.Println("other")
}
wyn
// Wyn
match n {
    0 => println("zero")
    1 => println("one")
    _ => println("other")
}

Pipe Operator (no Go equivalent)

wyn
// Wyn — no equivalent in Go
fn double(x: int) -> int { return x * 2 }
fn add1(x: int) -> int { return x + 1 }

var result = 5 |> add1 |> double  // 12

Performance Comparison

BenchmarkWynGo 1.24
fib(35)~48ms~57ms
spawn 1M~247ms / 2MB~279ms / 12MB
binary size32KB2.3MB
compile time~260ms~500ms

Key Differences

FeatureGoWyn
CompilationGo compilerC backend (TCC/gcc)
ConcurrencyGoroutinesGreen threads (same M:N model)
MemoryGCArena allocator
GenericsYes (1.18+)Basic (monomorphization)
Error handlingerror interfaceResult type + match
Package managergo modwyn pkg

MIT License