Skip to content

Instantly share code, notes, and snippets.

Struct Extensions Goals + Requirements

Author: Evan Ovadia

TL;DR: Struct extensions let library B add a fly_to method to library A’s Spaceship, and we want that. This doc talks about what they are, why we want them, and what they should do.

Status: Draft

TL;DR: Let’s add linear types to Mojo! This doc explains what they are, why they’re great, and how we could add them.

What’s a linear type?

It’s a type that cannot automatically go out of scope. If the user tries to let it go out of scope, the compiler shows an error, and recommends them to use a specific method (or methods) to destroy the object.

“Linear type” is an existing term that doesn’t fully convey what we’re talking about here though. We’re implementing privately destructed types; only a type’s methods can destroy it.

Haskell has this feature, and it largely works for them.