-
Notifications
You must be signed in to change notification settings - Fork 27
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
Let the element type and the endpoint types be different #121
Comments
Implementation is in #122 |
I still think the Instead of adding the method to julia> eltype_interval(::TypedEndpointsInterval{L,R,T}) where {L,R,T} = T
eltype_interval (generic function with 1 method)
julia> eltype_interval(::TypedEndpointsInterval{L,R,T}) where {L,R,T<:Number} = float(T)
eltype_interval (generic function with 2 methods)
julia> eltype_interval(1..2)
Float64
julia> eltype_interval(1..big(2))
BigFloat
julia> eltype_interval(1..1//2)
Float64 |
But... Why? The user writing julia> 10^16+1 ∈ (10^16+1)..10^17
true
julia> 10^16 ∈ (10^16+1)..10^17
false Maybe, just promoting two endpoints to the same type is best, as done basically everywhere in julia? |
Thanks for bringing this up! It is very important to be wary of. I think that it is a judgement call because if these sets were iterable, they would certainly return objects of type If we do not want to use |
Yes! Absolutely! The bounds are |
I think there may be some confusion about what I am proposing. I have added a code snippet to the original post above to clarify. I want to give the user maximum flexibility about what the endpoint types are. The behavior above would be preserved! |
@hyrodium regarding the type piracy issue, I do not think using
So the documented definition of |
@zsunberg
I understand your point, but there are big differences between
I am planning to replace |
How about having something like struct EndPoint{LR, OC, T}
x::T
end
const Interval{L,R,T} = Pair{EndPoint{:L,L,T}, EndPoint{:R,R,T}} where On a second thought, |
The rough conclusion that we reached in #117 is that the endpoint types should not necessarily be the same as the eltype.
I decided to implement this in a PR that I will submit shortly, but am filing this issue for conceptual discussion. The key lines that summarize the new implementation are:
There are some important choices I made with my implementation:
Interval
has endpoint types. There are no abstract types with endpoint type parameters. The type of the endpoint can be accessed with e.g.typeof(leftendpoint(i))
. This seemed to be the simplest and lowest-risk option, and we can change it later if necessary.eltype
as close to the endpoint types except forIntegers
(e.g.eltype(1..3//2)
would beRational
,eltype(1..2)
would beFloat64
), but this ended up feeling too special-case-y. I decided a better option would be to callfloat
to determine theeltype
from all endpoint types<:Number
in theInterval
constructor (i.e.eltype(1..3//2)
isFloat64
). This ended up feeling very nice and consistent and works well with other packages like Unitful.eltype
for aDomain
. It is "the type that best represents elements of the domain according to the criteria chosen by the programmer who created the domain." I think it is best to give users flexibility since it is hard to predict everythingDomain
s will be used for.What does everyone think?
The text was updated successfully, but these errors were encountered: