-
-
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
int, Int, and box #1470
Comments
There are actually 3 separate points here:
The last one will not really work, since |
I also find it a bit odd to use |
Any thoughts on the other two? |
Changing There are two things we need, so there should be two syntaxes: one is "make this be of type T or else raise an error" (currently convert), and the other is various user-defined behaviors around a type, like converting arrays. So there are two options: merge Thinking more about how we could do the second one, each call
where |
Would Also, I know there are some Another thing to think about: I wouldn't expect |
Those are some good points. As much as I would like to remove excess concepts, |
These are definitely good points, especially regarding |
Now that bits types and composites are all instances of DataType, I think we should revisit this. It's rather awkward trying to explain why you can add methods to BigInt but not to Int. |
This is definitely in the category of issues that keep me up at night. If/when we allow adding methods to
|
I've never really liked that some types have generic functions stuck inside them. It may be that all constructors should actually be methods of convert; i.e. make |
Do you suggest a special behaviour for 1 argument constructors? That would feel a bit strange for some types, like |
Fair point; making 1-argument constructors a special case certainly doesn't seem right. And especially for mutable types conversion and construction start to seem more different. |
Also, I didn't intend to suggest that 1 argument be a special case; I should have written |
I know you don't like it, but it's really convenient and no one's going to be happy if that goes away. I really don't see why it's a big problem. It fits quite nicely with the general idea of a single object being the locus of many different roles – BigInt is both a type and the way to construct that type. A little messy from the internals perspective, but very easy for humans to understand. Consider also the I also think we might want to introduce
It's a bit layered and nuanced, but I think it would remove a lot of repetitive definitions. |
I'm not against the notation |
The |
+1 for the I think there also needs to be some stricter style guidelines that come out of this discussion with the key being consistency across all kinds of types for construction/conversion. For example, as a user, I want to naturally be able to guess that to convert/coerce one type to another, I just need to use the lowercase name of the type I want; i.e. I think the construct/coerce part helps clean up the concepts from the developer perspective and I just want to make sure that users win here too with consistent Proper/lowercase usage. |
My proposal was actually to make all of these the names of types: |
Ah, that makes sense. I didn't quite piece it all together. That's great, I was more concerned about the consistency, so that solves the problem nicely (though will it be To make sure I understand, it defines conversion by construction (i.e. all conversions/coercions are a type of construction). So in building a new type, I would overload |
Yes, I think that's about it, although it does feel like a lot of different things to remember. In particular, I think this idea does imply that you would provide constructors for a type by adding methods to |
I'm hoping we'll be able to make this mostly backwards-compatible; method definitions on types will secretly add methods to The proposed design lets you "define what you can" and let everything else fall out. For example if a new type has a natural conversion to another one, you can just define Overall I'm in favor but I have a couple concerns.
I've never liked the idea that |
As a relative newcomer I like the idea of Also I find it odd that |
I just got bit by this trying to do an Just a ping. |
It does look like the more generic conversion functions are more popular:
I'd like to get rid of all the lower-case conversions except We should also remove |
+1 |
Love it. |
not quite done with renaming [ci skip]
Just for comparison, searching all METADATA packages gives:
|
I'm really pleased about this change. But one practical matter: to avoid deprecation warnings, does anyone see an alternative to forking a 0.4 version of packages? The syntax |
@timholy, you can use |
I'd thought about the rewriting part, but missed the |
Ah, although
suggests a certain amount of rewriting might be necessary anyway. |
For a range, you can do |
I know. I was just hoping for something I could do via search-replace with a text editor. I have a lot of packages :-). And a lot of lab-specific code. |
While I love this change, I don't like the idea of writing |
Also relevant: does |
Calling a constructor for a scalar type on a non-scalar input and implicitly mapping seems like a bad idea to me. |
Why is it a bad idea? Intuitively, it does not feel right, but I dislike doing a |
I agree with @tkelman. While writing It makes it explicit, both when writing and reading code that the operation is vectorized, and doesn't require any macro-ing or auto-vectorizing for the developer. |
@ViralBShah, it's the classic issue: does |
I agree |
I am in favour of having a generic way to vectorize things as well, and that the current method does not scale. The only issue I have with Perhaps we can retain some of those old definitions and not deprecate them yet - after all, you still have |
In my julia travels, I have found at least one case where I wonder whether vectorization is more useful than we generally credit. Say I have two images, map(Float32, img1)
map(x->map(Float32, x), img2) The implication is that I have to write more versions of whatever function this conversion appears inside of. Or maybe I'm missing a better way? |
That was exactly one of the cases that happened when I was working on a demo using Images. |
(This discussion is turning into an #8450 sequel. Map Syntax II: APL Strikes Back) |
@ViralBShah, FYI, @pao, good point, let's not add more to this here. |
I.e. write
Int(1.5)
instead ofint(1.5)
. See this thread for discussion:https://groups.google.com/d/topic/julia-dev/gy1HlWWcxBA/discussion
The text was updated successfully, but these errors were encountered: