-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: staged / meta / generated types ? #8472
Comments
As usual, your question shows an impressive mastery of all the factors. Here I was wondering if anyone was paying attention, then you go and show you've understood it all down to the letter... For #8432, I was mulling over how kosher it would be to call
Until we implement caching of stagedfunction expressions (and for cases where the created type won't have a unique signature for each call to the stagedfunction), we'll still have to maintain an So, bottom line is: I honestly don't yet know whether we need stagedtypes. In the cases I can foresee, it seems there's a good workaround (as long as people don't hate the |
Correction: won't work for fixed size arrays (duh). The stagedfunction won't have access to the actual sizes desired. So yeah, we probably need stagedtypes too (if we don't use tuples). |
related: #8322 |
You can declare types that correspond to integers, and thus pass the array size as a type. This would give a staged function access to the array size.
and then you have
|
I thought of that. I was thinking the user would have to deal with that ugliness, but actually we could hide it behind a wrapper:
and then have |
On 25 Sep 2014, at 16:26, Tim Holy notifications@github.com wrote:
|
I agree it would be better to have them. Right now I'm just a little too tuckered out to implement them myself, so if there's a short-term cheat available, I'll probably use it :). |
I think type families are the Haskell equivalent: https://www.haskell.org/haskellwiki/GHC/Type_families |
I've been considering how awesome After I saw NamedTuples, it seems pretty easy to register types and constructors in macros and generated functions. The only issue is that in Julia 0.5, |
Since #49187 was closed as a duplicate, I'll put this here: Here are a few example things this could be used for: Simpler
|
JuliaDiff/ChainRulesCore.jl#626 reminded me of this and inspired a question which I haven't found an answer to online: what would be the technical challenges for implementing a mutable version of NamedTuple? Something that can be allocated in one go (unlike a NamedTuple of Refs) and doesn't incur any reconstruction overhead (unlike a mutable struct wrapping a NamedTuple, as shown in #49187 (comment)). |
Or, maybe a mutable version of |
I intentionally left out |
Variance absolutely is important for subtyping. But AFAICT we can still treat things like |
Does this proposal also include the ability to
I have a potential use case for all of these operations in one of my libraries: I won't go into detail since it involves a lot of extraneous detail involving my domain of expertise, except upon request. |
Now that we have staged functions (or whatever name that will converge out of the discussion in #7474), can we be more greedy and request something similar to define types, i.e. where the type definition depends on the value of the parameters in a more general way than can currently be expressed?
This would allow the easy implementation of fixed size / stack allocated arrays ( #7568 ), and the construction of @timholy in #8432 to build custom types to be used in the cartesian iterators clearly expresses the need for this. It can also have many other interesting uses.
NTuple{N,Int}
andTuple{Int,Int,Float}
(in the notation of #8470 ) could be special cases (although I guess there are technical reasons that they need to be implemented separately?).The text was updated successfully, but these errors were encountered: