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

Type aliasing to shorten long type signatures while defining struct type #31952

Closed
runapp opened this issue May 7, 2019 · 3 comments
Closed
Labels
feature Indicates new feature / enhancement requests

Comments

@runapp
Copy link

runapp commented May 7, 2019

I'm defining a large structure like this

struct A{T<:Number}
  a::Matrix{T}
  b::Int
  c::Matrix{T}
end

In which I'd be happy to alias Matrix{T} to MT and limit this behavior in the scope of the definition. Simply I want to write code in the way of

struct A{T<:Number}
  MT=Matrix{T}
  a::MT
end

Can I make it within the current syntax?

@JeffBezanson
Copy link
Member

JeffBezanson commented May 7, 2019

This is tricky, since then it becomes harder to tell which statements specify field names. It also conflicts with possible default value syntax (#10146) (and with the existing @kwdef). So this seems unlikely.

@vtjnash vtjnash added the feature Indicates new feature / enhancement requests label May 7, 2019
@vtjnash
Copy link
Member

vtjnash commented May 7, 2019

FWIW, this does currently work:

julia> let
          MT = Matrix{S} where S
          struct A{T<:Number}
            a::MT{T}
          end
       end

@runapp
Copy link
Author

runapp commented May 8, 2019

@vtjnash It's exactly what I want. It surprises me that the struct definition is kept outside the let scope. I've been thinking of this way but given up too early. Thank you.

@runapp runapp closed this as completed May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

3 participants