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

Parametric Subtyping? #51025

Closed
ParadaCarleton opened this issue Aug 23, 2023 · 4 comments
Closed

Parametric Subtyping? #51025

ParadaCarleton opened this issue Aug 23, 2023 · 4 comments
Labels
duplicate Indicates similar issues or pull requests feature Indicates new feature / enhancement requests types and dispatch Types, subtyping and method dispatch

Comments

@ParadaCarleton
Copy link
Contributor

I'm not sure if parametric subtyping would be the right term, but the pattern I'm interested in is this:

# minimum example
struct Thing{T} <: supertype(T)
	field::T
end

# actual use case
struct UnitfulNumber{T <: Number} <: supertype(T)
	field::T
end

The motivation being that many Unitful objects can't deal with functions that have Real restrictions, because units have to subtype Number instead of Real. How difficult would it be to support this?

@brenhinkeller brenhinkeller added types and dispatch Types, subtyping and method dispatch feature Indicates new feature / enhancement requests labels Aug 23, 2023
@vchuravy
Copy link
Member

I think type predicates might be the right term, but I suspect for your use-case a limited set of predicates might be acceptable.

We have wanted something similar in the GPU ecosystem for wrapper arrays as well.

SubArray{T<:AbstractArray} <: storagetype(T)

@Seelengrab
Copy link
Contributor

Seelengrab commented Aug 24, 2023

This is basically a duplicate of #5 and/or traits. See also #23429, #18161, #6975 and numerous others, both here and on discourse. I don't think having a new issue for this is going to lead to a more centralized discussion.

@vchuravy
Copy link
Member

No it is not equivalent to #5 or interfaces/traits.

This is not about UnitfulNumber implementing the interface of the class number, but that the interface it implements is dependent on a parameter of the class is self.

Multiple Inheritance/Interface are an orthogonal concern.

@mbauman
Copy link
Member

mbauman commented Aug 24, 2023

Yeah, this is #8322.

@mbauman mbauman closed this as completed Aug 24, 2023
@mbauman mbauman reopened this Aug 24, 2023
@mbauman mbauman closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
@vchuravy vchuravy added the duplicate Indicates similar issues or pull requests label Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Indicates similar issues or pull requests feature Indicates new feature / enhancement requests types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

5 participants