OffchainLabs / arb-os

ArbOS operating system, to run at Layer 2 on Arbitrum chains. Also a compiler for Mini, the language in which ArbOS is written.
92 stars 21 forks source link

Traits #613

Open rachel-bousfield opened 3 years ago

rachel-bousfield commented 3 years ago

Types can now carry method data, which can provide type-checkable syntactic sugar.

type array<T> = struct {
    size: uint,
    topstep: uint,
    contents: block<T>,
    trait access: array_get::<T>,
};

The above declares an array type with the access trait equal to its specialized variant of the array_get function. Calling [] on an instance of this type as below performs a type-checked call.

let a = array_new::<string>(8, 0);
assert(a[0] == array_get::<string>(a, 0));

Additionally, this PR