Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Traits #613

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open

Traits #613

wants to merge 3 commits into from

Conversation

rachel-bousfield
Copy link
Contributor

@rachel-bousfield rachel-bousfield commented Sep 13, 2021

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

  • Makes type printing better by removing extraneous spacing and commas
  • Refactors type_tree to better reflect its purpose

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant