-
-
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
More Type Parameters? #6081
Comments
One potential issue with allowing any immutable type is that people aren't forced to be sensible. For example, integers and symbols are sensible type parameters, and perhaps so are polynomials - but what if people start using floating point numbers? I do support this, but that's something to bear in mind. |
+1. I actually added |
This would be very useful for numeric values with units of measure, as it could allow the computation units at compile time, so the actual computation shouldn't be any slower than the unit-free equivalent. SIUnits.jl gets around this by defining the power of each SI unit as a parameter, but this limits the ability to use any additional units (e.g. currency, non-SI units), and means that any prefixed values (e.g. nanometre) incurs overhead and rounding error by converting to and from the normalised form. |
Last I checked, SIUnits.jl also doesn't support fractional powers of units. |
[TIL - http://physics.stackexchange.com/questions/13245/dimensional-analysis-restricted-to-rational-exponents] |
Computing critical exponents is a cottage industry in certain areas of physics. |
thinking a little more about this, the biggest danger seems to be a lack of referential transparency. what if you allowed any value (including data types) in a type, and then someone mutated the value? it seems like it would be better if julia had a way of marking types "really immutable" which applies not just to the contents, but the contents of pointers. |
tl;dr; types should not contain values. there are the distinction between types and contents may be hazy at times, but the restricted set of type parameters is intended to help the user make this distinction. my feeling is that the type parameters should help describe the contents, but that generally the value should be unambiguously unchanged if the type parameters were lost. |
Type parameters are going to be compared by |
How about supporting arbitrary |
Bump. See discussion at 5999f53#commitcomment-7544035 |
Yes. Will do. |
Just a thought for when this is implemented: The type merge function in inference should probably aggressively drop type parameters (when merging similar types), similar to the way it aggressively widens to Tuple instead of trying to create successive Union types from specialized Tuples. |
Yes, that's a good idea. |
A NEWS item would be good. Also a manual update. |
allow all bits values as type parameters. closes #6081
(cherry picked from commit 90bf63c) [av skip] Conflicts: NEWS.md
Continuing from #5102 and prompted by https://groups.google.com/d/msg/julia-users/4dkqhnesnUc/5DY9S1HrARAJ
Currently only integers, symbols and types (and tuples of those) can be type parameters. Maybe it would be nice to extend this?
One example (from the discussion above) is factor rings of polynomials. I am new to this so may have the jargon slightly wrong, but basically they're like arithmetic with integers modulo some value, except that you're using polynomials and calculating the "modulus" relative to a polynomial. When implementing that with integers it is a great help to put the modulus in the type - the rings/fields are of different types depending on "n" and it saves space in the instances. The same is not (easily) possible with general polynomials (you have to either encode the polynomial as a tuple of integers, or us an integer index into a separate, global lookup table).
That's a neat, theoretically convincing case, but it's not very practical (particularly since when you do want this you are usually handling special cases that can be encoded as integers). I don't know if there are better examples.
The text was updated successfully, but these errors were encountered: