-
Notifications
You must be signed in to change notification settings - Fork 18
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
Order of type parameters is somewhat problematic #170
Comments
There seem to be three main ways the
The Intervals.jl package uses
If Julia allowed us to define the behaviour of specific number of type parameters we could end with something consistent but not currently possible:
Could you share any additional examples you have for why you thing the type should be last instead of first? I'm not opposed to making such a change we just need to justify the churn. |
Possibly this may be nice path forward: julia> using Intervals
julia> Intervals.Interval(::Type{L}, ::Type{R}) where {L <: Bound, R <: Bound} = Interval{T,L,R} where T
julia> Interval(Closed, Open)
Interval{T, Closed, Open} where T
julia> (::Type{Interval{T,L,R} where T})(a::S, b::S) where {S,L<:Bound,R<:Bound} = Interval{S,L,R}(a, b)
julia> Interval(Closed, Open)(1,2)
Interval{Int64, Closed, Open}(1, 2) |
I think my preferred path forward would be to just drop the bound parameters completely and just store them as symbols in the type. See #208 |
Some of methods in this package are inconsistent about the order
of the type parameters being used. E.g. in
In the constructor, you technically have
T===Closed
,L===Open
,R<:Any
.This isn't really a technical problem, since the package does not
defined any bounds on these type parameters, and as long as the package
doesn't do any other operations on these types, it's probably fine.
That said, there is certainly some tooling that expects that constructors
of the form
(::T)(args...) where T<:Type
actually return something that'sa subtype of
T
, which this violates, since:I would recommend reordering the parameters, so the type comes last.
If the concern is needing to write a bunch of extra parameters
that usually are not dispatched on, this can be handled via alias
as in
Base.Vararg vs NTuple
. E.g. in this case, you might have:and use
IntervalT
in method signatures.The text was updated successfully, but these errors were encountered: