Skip to content

Allow generic argument types #23

Description

@tonysparks

Right now generics are extremely primitive in their feature set. I'd like to enhance them to allow to be typed, which would enable two key features:

  1. Allowing constant values, which would be useful for declaring constants and array sizes
  2. Allowing trait types, which would constrain the generic types allowed.

Example syntax:

public struct StaticArray<SIZE:u32, T> {
   elements: [SIZE]T
}

...
var buffer = StaticArray<16, f32>{}
buffer[0] = 4f

For trait argument types:

trait Hashable<T> {
   hash: func<T>(T>): u32;
}
trait Comparable<T> {
   equals: func<T>(T,T): i32;
}

// Now we know any supplied K must have a method "hash" and V must have a method "equals"
public struct HashMap<K: Hashable<K>, V: Comparable<V>> {
 ...
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions