spool-lang / Spool-Legacy-Repo

Legacy repo for the Spool programming language.
3 stars 0 forks source link

Variant #21

Open RedstoneParadox opened 5 years ago

RedstoneParadox commented 5 years ago

Overview

Variant<T, U>, Variant<T, U, V>, and so on are special sealed classes (#?) used to represent situations where a value may be one of multiple types. It's sub-classes VariantT, VariantU, etc. are used to represent a value of each of these types.

For ergonomics, Silicon has T | U as shorthand for Variant<T, U> and so on. All subclasses of Variant also implement Box<T>(#19), so they get the benefits of implicit boxing and unboxing.


main {
    const variantFoo : Foo | Bar = new Foo();
    const variantBar : Foo | Bar = new Bar();

    println(variantFoo is Foo) // Prints 'true'
    println(variantBar is Foo) // Prints 'false'
}