JuliaApproximation / DomainSets.jl

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

Reomve `indomain` and type promotion in `in`? #26

Closed dlfivefifty closed 5 years ago

dlfivefifty commented 5 years ago

I think the current implementation of in adds more complexity than it removes:

function in(x, d::Domain)
   T = promote_type(typeof(x), eltype(d))
   T == Any && return false
   in(convert(T, x), convert(Domain{T}, d))
end

I think it would be simpler if each domain just overloads in, and can handle types however it sees fit...

daanhb commented 5 years ago

I agree that this function does not look very "julian". It does have semantic consequences if we change this (like it did when it was introduced).

Part of the practical rationale for having indomain is to reduce the chances of ambiguities. The in function is very popular to overload. As things stand, concrete domains don't have to specify the type of x in indomain. I seem to recall this was different before when simply using in, and x would have to be typed just to avoid ambiguity.

Another part of the reasoning is that it allows for generic processing of whatever x the user provides us with, regardless of the concrete domain. Currently, it seems we only ever call indomain with an x that has the element type of the domain, and in also generically tries to convert a vector to the element type of the domain.

Of course any domain is always free to override in and change this. Do you have an example of complexity being added, rather than removed, due to the current implementation of in?

dlfivefifty commented 5 years ago

I think those are good points, lets leave it as is for now. (I forgot why I filed this issue.)

daanhb commented 5 years ago

Okay. In general, feel free to make changes as you see fit, since you are clearly working on the code and we are not :-) We will adapt later.

dlfivefifty commented 5 years ago

I think I'm going to tag a version soon (and then tag ApproxFun). I don't know if I'll make many more changes.