Syntax for specifying type parameters values in associated function definitions
Opened this issue · 0 comments
osa1 commented
type Vec[T]:
data: Array[T]
len: U32
Using the type above, if I want to implement an associated function (should we call these "methods"?) on Vec[U8]
, there's currently no syntax to specify that T = U8
.
An idea:
# T is left generic, no need to specify
fn Vec.push(self, elem: T) = ...
# T is overridden after the type name
fn Vec[U8].readByte(byteIdx: Usize): U8 = ...
One disadvantage of this is that I can no longer easily search for function definitions, for example I can't do ag -w 'fn Vec.readByte'
and find the definition of it.
We can't put it after the function name as that's for the predicate list. E.g.
fn Vec.linearSearch[Eq[T]](find: T): Option[Usize] = ...