Closed daanhb closed 4 years ago
And I just realized that IntervalSets
has the same problem:
julia> using IntervalSets
julia> I = 0..1
0..1
julia> intersect(I, I)
0..1
julia> intersect(I, I, I)
ERROR: MethodError: no method matching iterate(::Interval{:closed,:closed,Int64})
Closest candidates are:
iterate(::Core.SimpleVector) at essentials.jl:568
iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
iterate(::ExponentialBackOff) at error.jl:199
...
Stacktrace:
[1] union!(::Set{Int64}, ::Interval{:closed,:closed,Int64}) at ./abstractset.jl:80
[2] Set{Int64}(::Interval{:closed,:closed,Int64}) at ./set.jl:10
[3] _Set(::Interval{:closed,:closed,Int64}, ::Base.HasEltype) at ./set.jl:23
[4] Set(::Interval{:closed,:closed,Int64}) at ./set.jl:21
[5] _shrink(::Function, ::Interval{:closed,:closed,Int64}, ::Tuple{Interval{:closed,:closed,Int64},Interval{:closed,:closed,Int64}}) at ./array.jl:2396
[6] intersect(::Interval{:closed,:closed,Int64}, ::Interval{:closed,:closed,Int64}, ::Interval{:closed,:closed,Int64}) at ./array.jl:2400
[7] top-level scope at none:0
I filed this issue to remember the problem. In the code where I hit it, I replaced intersect(list_of_domains...)
with reduce(intersect, list_of_domains)
and that works.
This issue is not so bad, since the problem doesn't arise when using ∩
, which only calls a two-argument intersect
. Closing this for now until it comes up in a case where it is clearly a problem.
A
Domain
has aneltype
, but it is not iterable. This leads to some problems when using functionality that is defined with sets in mind.Here is a simple problem:
You can not create a Set that contains a Domain this way. The way to do it is:
That is fair enough, but it leads to other issues. For example, we can not compute the intersection of three domains:
The two-argument function succeeds because we defined it ourselves. The three-argument version fails because the fallback in Julia tries to make a Set out of the domains.
Also, we currently have this inconsistent behaviour of
union
:Of course we could fix intersect and union ourselves, but perhaps there is a better change that would make
Domain
integrate better with the existing Julia functions.