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

Passing a parameter from a parametric parameter to an abstract parametric type #36377

Closed
EricForgy opened this issue Jun 21, 2020 · 1 comment

Comments

@EricForgy
Copy link
Contributor

EricForgy commented Jun 21, 2020

Hi,

This issue stems from a question I asked on Julia Slack and @jakobnissen, who was helping me (thanks again!), thought it was worth submitting an issue about it.

I have an existing parametric type of the form E{S,C} and an abstract parametric type of the form I{S,C}.

I was trying to define a new parametric subtype CS of I. I initially implemented it like

struct CS{ES,EC,S} <: I{S,EC}

where ES and EC are parameters of the existing E.

Then, I felt it would be logically more clear if instead of sticking ES and EC from E directly as parameters of CS, if I just made E{ES,EC} a parameter of CS. Something like

struct CS{E{ES,EC},S} where {ES,EC,S} <: I{S,EC}

Unfortunately, it seems this syntax is unavailable.

@jakobnissen commented:

I think thatt's impossible. A shame, it would make type signatures for things like static arrays and subarrays much more concise.

He couldn't find an issue related to this and, after asking if it made sense, he said it would make sense to submit an issue so here you go :)

I don't know the ramifications to static arrays or subarrays, but it would make my code a little cleaner I think if this syntax were available. Are there any existing issues related to this that we've missed?

Edit: The more I look at it, the more I think

struct CS{E{ES,EC},S} where {ES,EC,S} <: I{S,EC}

should be valid syntax so I'm almost certain this has been discussed. To my eye, it seems perfectly consistent with what we do with methods.

Edit^2: Or maybe

struct CS{E{ES,EC},S} <: I{S,EC}

could just work without the where 🤔

@EricForgy EricForgy changed the title Passing a parameter from parametric parameter to an abstract parametric type Passing a parameter from a parametric parameter to an abstract parametric type Jun 21, 2020
@JeffBezanson
Copy link
Member

This would probably be difficult to implement, since it breaks fundamental assumptions about the structure of types. For field types, it can be implemented on top of #18466 (by calling a function to pull the parameter out of E when the first parameter to CS becomes known), but the supertype is trickier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants