-
-
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
computed subtyping declarations #8322
Comments
The problem with 1 and 2 is that Foo1 and Foo2 are themselves types, so they need a place in the type hierarchy. With this extension In case 3, C{Int} is a problem since we don't know that type |
For case 3, the very notation
For cases 1 and 2, I of course didn't think of the problem you point, but the same solution of making |
Making Foo1 a subtype of Any might work; I'll have to think about it. |
Thanks. I realize I didn't give my real use case. My first try was relying on 3:
So my second try was naturally using 2:
So I seem to not be able to express that my |
@JeffBezanson I can give two more examples where these ideas are relevant. In #8176, we have been discussing if an array view should be a
or maybe even
In this thread, we discussed the possibility of storing a matrix of dual numbers as It appears to me that, in terms of the type lattice, this possibility is not invalid, although it changes the lattice structure a bit. It is different from the present system, but I think it could make sense that the location in the type hierarchy of a parametric type depends on the values of the parameters. |
A simpler but related problem is arithmetic with integer type parameters, e.g. a trajectory in
|
If it were available, ColorTypes would use abstract type Colorant{T,N} end # T is element type, N is number of color channels
abstract type Color{T, N} <: Colorant{T,N} end # types with no alpha channel
abstract type TransparentColor{T,N,C<:Color{T,N-1}} <: Colorant{T,N} end where the Or even better: abstract type Colorant{T,N::Int} end # T is element type, N is number of color channels
abstract type Color{T,N::Int} <: Colorant{T,N} end # types with no alpha channel
abstract type TransparentColor{T,N::Int,C<:Color{T,N-1}} <: Colorant{T,N} end since that would allow one to express the fact that |
Another important use case: units are often incompatible with currently-existing code, because units subtype struct UnitfulNumber{T <: Number} <: supertype(T)
field::T
end |
Three things that would be nice to have:
type Foo1{T} <: T end
type Foo2{T} <: (T==Int ? Signed : Unsigned) end
type Foo3{C}; a::C{Int} end
There are numerous related discussions on the lists, but I wanted to know if these requests are just not yet implemented or are "won't fix".
The problem is that at method/type definition time, type parameters are
TypeVar
objects and not the type they refer to at instanciation time.The first time I hit this was when defining a method like
fun{C}(collection::C, x::eltype{C}) = ...
: there was no erros, because there is a fallbackeltype(x) = Any
, but this didn't do what I intended (this example seems related to point 2, but is maybe trickier to implement). Similarly it's unexpected thatFoo2{Int}.super == Unsigned
, this would deserve a clarification in the docs.Another real use case of point 2. just came up from Bill Hart on julia-dev:
My hope that this gets implemented comes from the type section of the manual: "because Julia is a dynamically typed language and doesn’t need to make all type decisions at compile time, many traditional difficulties encountered in static parametric type systems can be relatively easily handled" :)
The text was updated successfully, but these errors were encountered: