Skip to content
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

width of integer & similar intervals #21

Closed
tpapp opened this issue Oct 19, 2017 · 6 comments
Closed

width of integer & similar intervals #21

tpapp opened this issue Oct 19, 2017 · 6 comments

Comments

@tpapp
Copy link
Contributor

tpapp commented Oct 19, 2017

Currently

julia> width(Date(1980,1,1)..Date(1980,1,10))
9 days

julia> width(1..10)
9

which makes sense in some contexts, but in others 10 would be a better choice (eg duration of a spell represented by the interval).

I would like to initiate discussion on how to handle this. The following come to mind:

  1. Encourage the user to redefine width with +1 or equivalent whenever that makes sense, but don't do this automatically. Problem: width(1.0..10.0) ≠ width(1..10) if one redefines it. For Date and similar this would not be a problem.

  2. To implement 1. more elegantly, one can define a trait, eg Date would have the trait RepresentsDuration(), width would test for that, and add 1 accordingly. The default would be not having this trait. Problem: same as above, advantage: user could inspect this behavior for generic types.

  3. Add another generic function, eg span, which adds 1 whenever applicable. Again, with or without trait.

Thoughts?

@timholy
Copy link
Member

timholy commented Oct 19, 2017

How about length and define it only for Integer intervals?

@tpapp
Copy link
Contributor Author

tpapp commented Oct 19, 2017

Thanks for the suggestion, see PR #22.

timholy pushed a commit that referenced this issue Oct 20, 2017
See discussion at
#21, this should
fix the issue.
@dlfivefifty
Copy link
Member

We now have duration. But probably the current behaviour is wrong and duration of dates should return a date?

julia> duration(Date(1980,1,1)..Date(1980,1,10))
10

julia> duration(1..10)
10

@timholy
Copy link
Member

timholy commented Sep 14, 2018

Yes, definitely the units need to be preserved. And just to check (sorry, short on time), I think we got rid of length, right?

@dlfivefifty
Copy link
Member

dlfivefifty commented Sep 15, 2018

Yes we got rid of length: length is a notion of cardinality, not measure, so it was an abuse of terminology, and also doesn't play well with Base's assumptions on length.

If anything, the following is the most reasonable definition of length:

length(d::AbstractInterval) = (@assert !isempty(d); ℵ₁)

@hyrodium
Copy link
Collaborator

length was removed #31, so I'll close this issue. Note that duration will also be removed in the future release. (#102)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants