Skip to content

width of integer & similar intervals #21

Closed
@tpapp

Description

@tpapp

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions