Swan Lake Beta3 is here.
import ballerina/io;

public function main() {
    // 1 belongs to `int`.
    io:println(1 is int);
    // [10, 20, 30] belongs to `int[]`.
    io:println([10, 20, 30] is int[]);

}

Structural Typing

Typing in Ballerina is structural: a type describes a set of values. Ballerina has semantic subtyping: subtype means subset. Universe of values is partitioned into basic types. Each value belongs to exactly one basic type. Can think of each value as being tagged with its basic type. There is a complexity in making structural typing work with mutation.

Immutable basic types (so far): nil, boolean, int, float, string

Mutable basic types (so far): array, map, and record

import ballerina/io;
public function main() {
    io:println(1 is int);

1 belongs to int.

    io:println([10, 20, 30] is int[]);

[10, 20, 30] belongs to int[].

}
bal run structural_typing.bal
true
true
import ballerina/io;

public function main() {
    // 1 belongs to `int`.
    io:println(1 is int);
    // [10, 20, 30] belongs to `int[]`.
    io:println([10, 20, 30] is int[]);

}

Structural Typing

Typing in Ballerina is structural: a type describes a set of values. Ballerina has semantic subtyping: subtype means subset. Universe of values is partitioned into basic types. Each value belongs to exactly one basic type. Can think of each value as being tagged with its basic type. There is a complexity in making structural typing work with mutation.

Immutable basic types (so far): nil, boolean, int, float, string

Mutable basic types (so far): array, map, and record

import ballerina/io;
public function main() {
    io:println(1 is int);

1 belongs to int.

    io:println([10, 20, 30] is int[]);

[10, 20, 30] belongs to int[].

}
bal run structural_typing.bal
true
true
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand