JuliaApproximation / DomainSets.jl

A Julia package for describing domains as continuous sets of elements
MIT License
72 stars 12 forks source link

Domains, Intervals, etc. should be traits, not types #18

Closed dlfivefifty closed 3 years ago

dlfivefifty commented 6 years ago

This is the evolution of the ideas that have been floating around about domains being an interface, not a type.

I think to support domains from other packages and Base (like IntervalSets, or Set) we should re-structure this package a bit to use traits. That is, we'd have the following:

abstract type DomainStyle end
struct IntervalStyle <: DomainStyle end
struct PointStyle <: DomainStyle end
struct SetStyle{T} <: DomainStyle end

DomainStyle(::Type{<:IntervalSets.Interval}) = IntervalStyle()
DomainStyle(::Type{<:Number}) = PointStyle()
DomainStyle(::Type{<:AbstractArray{T}}) where T = SetStyle{T}()
DomainStyle(::Type{<:AbstractSet{T}}) where T = SetStyle{T}()

I think the best way to implement this proposal is to do this in a separate branch, side-by-side with ApproxFun's adoption of Domains.jl. The result will be that, for example, we can do f = Fun(exp, [1,2,3]) for a function supported on the points [1,2,3] instead of g = Fun(exp, union(Point(1), Point(2), Point(3)), and have the property that domain(f) === [1,2,3]. And also domain(Fun(exp, 1..2)) === 1..2.

This will ease the "wrapper bloat" of trying to make everything a subtype Domain.

dlfivefifty commented 6 years ago

Also, this change if implemented properly won't change the current behaviour, so it should be best-of-both.

dlfivefifty commented 6 years ago

Sorry, that last commit doesn't close this issue