Skip to content

vine: impl derivation #169

Open
Open
@tjjfvi

Description

@tjjfvi

Introduce Tuple and Object traits

trait Tuple[Tuple, Init, Rest] {
  fn deconstruct(tuple: Tuple) -> (Init, Rest);
  fn reconstruct(init: Init, rest: Rest) -> Tuple;
}

trait Object[Object, Init, Rest] {
  const key: String;
  fn deconstruct(object: Object) -> (Init, Rest);
  fn reconstruct(init: Init, rest: Rest) -> Object;
}

The compiler would automatically implement Tuple and Object for all non-empty tuple and object types; e.g. Tuple[(A, B, C), A, (B, C)] and Object[{ a: A, b: B, c: C }, A, { b: B, c: C }]. The order in which object types are broken down would not be guaranteed.

This allows traits to be inductively implemented for all tuple/object types by providing impls for (), {}, and types implementing Tuple/Object.

For struct types, introduce an additional trait

trait Struct[Struct, Data] {
  const name: String;
  fn deconstruct(self: Struct) -> Data;
  fn reconstruct(data: Data) -> Struct;
}

Not sure how best to make implementations that use this impl to be opt-in.

Also not sure how best to handle enums.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tbdhas open design questionsvine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions