-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generics #527
Comments
Generics are planned, but not implemented yet. I hope that some day, I will add something like this to stdlib: class List[T]:
ptr: byte*
length: long
alloc: long
@inline
def append(self, elem: T) -> None:
...
def extend(self, elems: T*, count: long) -> None:
...
def end(self) -> T*:
return &self->ptr[self->length]
# ...other methods... With this in stdlib, you could write: import "stdlib/list.jou"
import "stdlib/io.jou"
def main() -> int:
nums = List[int]{}
nums.append(1)
nums.append(2)
nums.append(3)
# Output: 1
# Output: 2
# Output: 3
for p = nums.ptr; p < nums.end(); p++:
printf("%d\n", nums.ptr[i])
return 0 There is a reason why If |
Ok! I was actually asking because I noticed that you use Pointers a lot instead of a List type and after not finding generics supposed that was the reason why :D. How hard would inlining be to implement in jou? |
For inlining, the compiler needs to:
"3." is the most difficult, of course, but everything seems doable. |
Generics would also be useful for plain old functions. There is currently no I recently added |
With generics should probably also come compile time type checking |
Types are already checked at compile time. Jou's type checking is very similar to C: you can do dumb things with |
I meant it as in foo = Variant[Bar | Baz](xyz)
if constrained(foo, Variant[Bar]):
...
elif constrained(foo, Variant[Baz]):
... |
It seems like you are talking about tagged unions, like Rust's At some point I was going to add tagged unions, but now I feel like it's a Rust feature that doesn't really belong in Jou. I might change my mind eventually though. |
I assume Jou doesn't do errors as a type then? :D |
You're right. Jou is a simple language, not a full-featured language. |
Actually, how do you handle exceptions/errors in Jou? I can't find anything about it in the docs (I'm on IRC and Discord if you want to talk about this elsewhere) |
I created #533.
I will go to sleep soon. I might have more time tomorrow... :) |
I couldn't find anything on generics, is that a language concept yet? Generally something that happens later though
The text was updated successfully, but these errors were encountered: