-
-
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
"hard" type alias or Inheritance from a concrete type #9821
Comments
See also #2248 |
I don't understand "Let function bodies only do, what is implied by their function name". The example seems to be restricting matrix multiply to arrays with appropriate sizes, using types instead of an |
Here is my guess as to the single biggest difficulty. Let's say we have:
So The reason I think this is the fundamental problem is that it holds no matter how we make |
Oh yes, you pointed this out another time, sorry to make you repeat yourself. |
Possibly related to the discussion we had about |
Ha! Yeah, I like the idea of overloading call(::Function, ...), especially for bench marking reasons. |
I just realized how truly evil jeff's example is. function f(x::Float64, y::Float64)
...
convert(Float64, g(x+1, y-1))
end Doesn't imply function f(x::X{Float64}, y::Float64)
...
convert(X{Float64}, g(x+1, y-1))
end Cruel world... function f{T <: Float64}(x::T, y::T)
...
convert(T, g(x+1, y-1))
end Looks a lot more managable |
To come back to the other question: Also, the size of the array becomes a constant inside the body correct? |
All this is a lot about type hierarchies and the question weather functions have been defined for concrete types or not. If one has an interface for a type (say FixedVector) it will likely only have less than 5 methods (setindex!, getindex, size, ...?) If all other methods are implemented ontop of the abstract type one will always gain everything when subtyping from the abstract type and implementing the interface. So as pointed in #7568 we may simply implement the methods for the fixed size array and can later have "the real one" based on tuples. The only issue was construction but haven't we even solved that with the call syntax? |
And on letting the size of an array be a type parameter: This would not work for vectors currently (we have resize) but in ND for N>=2 there don't seem to be an issue. |
I'm trying to understand the examples, and to me, reusing an existing type I'm sure some of the types of issues that you bring up can be solved by But seen in that light, a number of your examples include subtyping of I think that solving many of the issues that you bring up has to start |
I think you're right. # I must admit, I don't really know what I'm doing here, but if something relies on the exact number
# of bits, this type hierarchy could achieve this, without using concrete bitstypes:
abstract FloatingPoint{Bits}
bitstype 32 Float32 <: FloatingPoint{32}
#e.g.
+{T <: FloatingPoint}(x::T, y::T) = box(T, add_float(unbox(T, x),unbox(T, y)))
# Now I can define my own floatingpoint, with all the relevant functionality working:
abstract Meter{T} <: FloatingPoint{T}
bitstype 32 Meter32 <: Meter{32} This is just a quick idea, someone with more knowledge about Julia's internals should probably flesh out something better. While similar concepts apply to NTuple it seems a little bit more complicated to me. But the reasons behind this could be simply, that I've been more involved with FixedSizeVectors. I hope that at some point, valid SPIR code can be emitted for FixedSizeArrays, so we can compile to the GPU seamlessly. This on its own further complicates issues. |
I once asked a similar question on the mailing list: In Haskell these things are somewhat possible, constructed with |
@mauro3 Actually, you can use the
For example, there's a type class Instead of type classes, in Julia you could define macros like
and that would define methods for the desired functions with appropriate unwrappings and wrappings. To mimic Haskell's constraints like In that vein, you could actually define |
closing as this is the "fragile base class problem", as jeff pointed out above |
I've addressed this feature multiple times, but never really got feedback on it, so I decided to open an issue for it, as I keep coming back to it as a very elegant solution to many problems.
I hope you can answer at least, how feasible this is, what needs to be done for it (so that I can maybe implement it myself, if no one has the time), or explain me why this is a silly idea.
What I want:
Intended semantic: The first type (e.g. RGB) is a either subtype of the second (e.g NTuple), or has the type Union(RGB, NTuple).
I'm not sure what makes more sense. But it should solve the following problem:
This behavior is wanted in a myriad of cases and I've seen workarounds for this situation in many packages (including mine).
Examples
A few examples, which can be elegantly implemented with this feature, which assume, that NTuple implements common, simd accelerated, vector operations
Adding functions to an existing type:
To further dwell on the point, that we can have a diversity of simd accelerated Vector types, with minimal re-implementation of common functionality, here is another example:
Adding Semantic to generic Types
Now the big magic, won by more type information
This would be pretty much the paradise for any visualization library. Also, visual debugging is made a lot easier, as the debugger doesn't need any magic to infer how it needs to visualize some random variable.
But this matters for more than that, as it becomes easier to do the correct thing with any value.
I you want to see something else, for example the pixel of the image in RGB space, you can simply reinterpret the RGB to Point (which has O(1)), which can be useful to make out color clusters.
Let function bodies only do, what is implied by their function name
Compare these two implementations:
This all is mostly graphic related, which isn't a big surprise considering my background. But I'm pretty sure, that there are good use cases for other fields ;)
But I better not iterate more use cases here, as this would turn even more into a novel.
Hope we can realize this in some way!
Best,
Simon
The text was updated successfully, but these errors were encountered: