Skip to content
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

Variadic generics parametrized by value #7101

Open
dmitriy-serdyuk opened this issue Nov 21, 2018 · 2 comments
Open

Variadic generics parametrized by value #7101

dmitriy-serdyuk opened this issue Nov 21, 2018 · 2 comments

Comments

@dmitriy-serdyuk
Copy link

Crystal allows to parametrize generics by integer:

class A(T) end
puts A(2).new()
#<A(2):0x10fb4dff0>

Unfortunately, this doesn't work with variadic generics:

class A(*T) end
puts A(2).new()
Error in tst.cr:2: argument to Tuple must be a type, not 2

puts A(2).new()
     ^

Related to #4337

@asterite
Copy link
Member

Use case? I think it's fine that it doesn't compile.

@dmitriy-serdyuk
Copy link
Author

It could be useful for statically typed n-dimensional arrays when you don't know n in advance.

Imagine matrix multiplication operator that accepts only right inputs:

def dot(first : Matrix(N, M), second : Matrix(M, K)) : Matrix(N, K)
    ....
end

This wouldn't work for n-dimensional case.

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

No branches or pull requests

4 participants