-
Notifications
You must be signed in to change notification settings - Fork 165
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
Feature request: Rank polymorphism thru size and type lists #1994
Comments
What exactly does
Does Why not a definition of
so that the map is both variadic and rank polymorphic? I think @athas's vision with this stuff is to support some APL-like syntax; i.e., rank polymorphism via function application as mentioned in the post. So, rather than having (with the above variadic/rank polymorphic map) having to write
(and at this point maybe it'd be better to call for some arrays
which the compiler then translates to
We actually looked into rank polymorphic function application and I hacked up a couple of prototypes. As mentioned in the post, the type checking is pretty non-trivial (whole PhD dissertations have been written on this issue and haven't solved it). I'd still like
As for variadic functions, maybe @athas can comment on that. I haven't thought much about it but obviously a generic zip is nicer that having zip |
I don't think variadic functions are possible to combine with type inference. It's not even clear how you as a programmer would write them (your examples are all just types, not definitions). Rank polymorphism is certainly something we (sort of) actively investigate, and @zfnmxt did a good job layout out the current vision. In particular, it is rooted in not complicating the function type system itself. There's discussion and work here: #1747 |
I propose to implement rank polymorphism by introducing size and types lists type arguments.
Inspired by the blog in https://futhark-lang.org/blog/2022-10-03-futhark-on-arraycast.html
A size or type list can be expanded thanks a
..
suffix in a function declaration. This suffix be followed by indices, in case there is an ambiguity on the expansion to be performed, like soa[t]..t
For example
The
..
suffix can also be used in function types. For example,Single size can also be expanded like so
Functional function can then be generalized as follows. Note that variadic functions are now possible.
SOAC functions can then be generalized as follows
Array functions can then be generalized as follows
Zip functions can then be generalized as follows
TBH, I have no idea about the feasibility or complexity on implementing this. I've encountered the need for more rank polymorphism when exploring how to implement a futhark onnx runtime. The only way to go around with current the current futhark implementation would be to template everything, which could work, but be quite ugly. Ideally, I would much prefer have some independent generic futhark code base to translate an onnx graph in a pretty direct manner.
The text was updated successfully, but these errors were encountered: